SDK version 3.0 change to user attributes value NSObject makes swift API awkward
bobergj opened this issue · 5 comments
From release notes:
Previously, notification listeners were only given string-valued user attributes because only strings could be passed into various method calls. That is no longer the case. The ActivateListener and TrackListener interfaces now receive user attributes as NSDictionary<NSString *, NSObject *> * _Nullable instead of NSDictionary<NSString *,NSString *> * _Nonnull.
This makes the Swift API awkward because there in Swift there is no implicit conversion to NSObject.
Eg, we get a lot of errors:
Cannot convert return expression of type '[String : String]' to return type '[String : NSObject]?'
Cannot convert return expression of type '[String : Any]' to return type '[String : NSObject]?'
The Objective-C header should instead declare the dictionary as NSDictionary<NSString *, id> *
which gets bridged to [String : Any]
.
Alternatively, you could put a NS_REFINED_FOR_SWIFT on those API methods and provide a type safe Swift API.
+1
This issue is really annoying, On my side i was able to make it work by casting (String to NSString, Int to NSNumber, etc) but it is a major hassle and not convenient at all
Thanks for reporting this issue @bobergj . We will take a look and get back to you.
We are looking at a patch release using NSDictionary<NSString*,id>*. We are also updating event tags and all attribute calls where this would be an issue. Again, thanks for reporting!