ios_sdk: Nullability annotations needed to prevent silent-ish failures in Swift 3
I recently discovered a bug with Swift 3 while using the Adjust SDK, which can be fixed by adding nullability annotations. The Swift bug is filed here. The following code will work in Swift 2.3, but it will fail in Swift 3:
let criteo = ADJCriteo(id: "some_id", price: 1.0, quantity: 1) // Returns an implicitly unwrapped optional, since ADJCriteo.h has no nullability annotations
let str = ADJCriteo.createCriteoVB(from: [criteo])
/*
The above method take [Any]! because there are no nullability annotations.
It then returns nil because of the mentioned Swift bug.
When this class method checks what kind of class the criteo object is, it returns _SwiftValue, which causes this to fail
*/
This can be easily prevented from happening by adding nullability annotations to ADJCriteo.h. It’ll also generally make this SDK more friendly for Swift users 😊.
Currently, the easy workaround is to just explicitly unwrap the ADJCriteo object upon creation with a !.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 15 (7 by maintainers)
Looks good! thanks!!
That’s the only example I remember encountering directly. Finding more would require auditing the SDK public headers for those that are missing nulllability annotations or missing type annotiaons for collections (i.e. NSArray instead of NSArray<Type *>). Fixing and cleaning up those would be sufficient to trigger warnings in people’s projects and prevent this kind of bug.