0

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)}];

1 Answer 1

1

“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])
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Oh for those helpful error messages, didn't even think that the problem was with the enum

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.