Reputation: 738
I'm trying to send some data from a swift file to an objective-c file. I have all the bridging headers and whatnot configured, such that when I pass a string, it can be used by the objective-c file. However, I would really like to pass an NSArray, and when I do this, I get a whole slew of errors starting with
[Swift._NSSwiftArrayImpl length]: unrecognized selector sent to instance 0x6000000363a0
I saw Array element cannot be bridged to Objective-C but solutions on that page, which were switching the Array to an NSArray in swift, and making all the objects in the array AnyObjects, did not work; besides, the error I got is different from the error on the aforementioned question. This is my condensed code:
Swift:
var myNSArray = ["foo","bar"]
objectiveCClassInstance.arrayPassFunction(myNSArray)
.h:
- (void)arrayPassFunction:(NSArray*)myObjectiveCNSArray;
.m:
- (void)arrayPassFunction:(NSArray*)myObjectiveCNSArray{
NSLog(myObjectiveCNSArray);
}
Upvotes: 2
Views: 527
Reputation: 299345
Your call to NSLog
is incorrect. The first parameter of NSLog
is the format string. You meant:
NSLog(@"%@", myObjectiveCNSArray);
I'm surprised you didn't get a warning about this.
Upvotes: 3