Reputation: 7975
I have an Obj-c superclass, with
@property (strong, nonatomic) NSMutableArray *sectionChanges;
And in Swift I am trying to add a dictionary to it:
self.sectionChanges.addObject([NSFetchedResultsChangeType.Insert: 1])
We get
'AnyObject' does not have a member named 'Key'
I have tried a lot of options:
self.sectionChanges.addObject([NSFetchedResultsChangeType.Insert: 1] as NSDictionary)
Changed the error to
Type 'NSFetchedResultsChangeType' does not conform to protocol 'NSCopying'
Then I try:
self.sectionChanges.addObject([Int(NSFetchedResultsChangeType.Insert): 1] as NSDictionary)
and get:
Cannot invoke 'init' with an argument of type 'NSDictionary'
Running out of options... Then same code in Obj-c is simple:
[self.sectionChanges addObject:@{@(type): @(sectionIndex)}];
Upvotes: 0
Views: 1978
Reputation: 6377
“Swift imports as a Swift enumeration any C-style enumeration marked with the NS_ENUM macro.”
Excerpt From: Apple Inc. “Using Swift with Cocoa and Objective-C.” iBooks. https://itun.es/tw/1u3-0.l
So NSFetchedResultsChangeType
is a Swift enumeration now, and you can't pass it to Objetive-C.
You might want to try this:
self.sectionChanges.addObject([NSFetchedResultsChangeType.Insert.rawValue: 1])
Upvotes: 1