Superwall-iOS icon indicating copy to clipboard operation
Superwall-iOS copied to clipboard

[BUG]"{\"Err\":\"Invalid execution context JSON: expected ident at line 1 column 2\"}"

Open songzhiming opened this issue 1 month ago • 6 comments

`

struct AAA: Codable {
    var totalMoveGoalsMet: Int
}
class BB: HostContext {
    var aaa: AAA
    func computedProperty(name: String, args: String, callback: ResultCallback) {
        callback.onResult(result: aaa.totalMoveGoalsMet.string)
    }
        
    func deviceProperty(name: String, args: String, callback: ResultCallback) {
        callback.onResult(result: "")
    }     
}

func test()  {
    let str = evaluateWithContext(definition: "totalMoveGoalsMet == 3500", context: BB(aaa: AAA(totalMoveGoalsMet: 4000)))
} 

` New issue checklist

  • [ ] I have reviewed the README and documentation
  • [ ] I have searched existing issues and this is not a duplicate
  • [ ] I have attempted to reproduce the issue and include an example project.

General information

  • Superwall version:
  • iOS version(s):
  • CocoaPods/Carthage version (if applicable):
  • Xcode version:
  • Devices/Simulators affected:
  • Reproducible in the demo project? (Yes/No):
  • Related issues:

Describe the bug

A clear and concise description of what the bug is. The more detail you can provide the faster our team will be able to triage and resolve the issue.

Steps to reproduce

Please also include a description of expected vs. actual behaviour

Other Information

e.g. stacktraces, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.

songzhiming avatar Oct 19 '25 14:10 songzhiming

SW-4105

linear[bot] avatar Oct 19 '25 14:10 linear[bot]

SW-4105 @linear

Image

songzhiming avatar Oct 19 '25 15:10 songzhiming

Hi, it looks like you're trying to use Superscript outside of Superwall. Can you explain more about why you want to do this?

yusuftor avatar Oct 20 '25 10:10 yusuftor

https://github.com/superwall/Superscript-iOS ,I am using this library to parse CEL (Constraint Expression Language) expressions. @yusuftor

Image

songzhiming avatar Oct 20 '25 12:10 songzhiming

The issue is you're only passing in the expression to evaluate in the definition, rather than the whole context as a string, where the context looks like this:

struct ExecutionContext: Codable {
  let variables: PassableMap
  let computed: [String: [PassableValue]]
  let device: [String: [PassableValue]]
  let expression: String
}

Take a look at CELEvaluator.swift to see how we do it.

yusuftor avatar Oct 22 '25 13:10 yusuftor

@yusuftor Thank you for your guidance, but I still don’t understand. Could you write a demo? What I actually want is something similar to the effect of NSPredicate or NSExpression.

        /// The object can be a struct or JSON.
        let object = ["count": 10]
        let predicate = NSPredicate(format: "count > 10")
        let result = predicate.evaluate(with: object)
        print("result----\(result)")   false
        
        
        let expression = NSExpression(format: "count + 1")
        let result1 = expression.expressionValue(with: object, context: nil)
    
        print("result1----\(result1)")  11

songzhiming avatar Oct 23 '25 02:10 songzhiming