I am trying to convert array of Swift Int64 into NSArray with NSNumber values.
@interface A : NSObject
- (void)bar:(NSArray *)tips;
@end
Swift class inherits this Objective-C class:
class B : A {
    func foo(tips : [Int64]) {
        self.bar(tips)
    }
}
Swift code does not compile with the following error:
Type '[Int64]' does not conform to protocol 'AnyObject'
How can I convert [Int64] into NSArray with NSNumber instances?
P.S. I tried number of things and could not find a simple way to do this:
self.bar(NSArray(array: tips))
self.bar(tips as NSArray)
EDIT: this question relates does not relate to trying to build new NSArray from separate Int64 objects, but to convert existing array [Int64] into NSArray
Map over it:
func foo(tips : [Int64]) {
    bar(tips.map { NSNumber(longLong: $0) })
}
This will build a new array, wrapping all Int64 in NSNumber, this new array should be castable to NSArray with no problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With