Superwall-iOS
Superwall-iOS copied to clipboard
[BUG]"{\"Err\":\"Invalid execution context JSON: expected ident at line 1 column 2\"}"
`
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
READMEand 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
Superwallversion:- 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.
Hi, it looks like you're trying to use Superscript outside of Superwall. Can you explain more about why you want to do this?
https://github.com/superwall/Superscript-iOS ,I am using this library to parse CEL (Constraint Expression Language) expressions. @yusuftor
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 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