quantumpotato
quantumpotato

Reputation: 9767

[AnyObject]? does not have a member named 'mutableCopy'

var sortingArray:NSMutableArray?

sortingArray = fetchedResultsController?.fetchedObjects.mutableCopy()

I get the error

[AnyObject]? does not have a member named 'mutableCopy'

How do I pull out a mutable copy?

Upvotes: 1

Views: 1095

Answers (1)

Antonio
Antonio

Reputation: 72750

The fetchedObjects property of NSFetchedResultsController is defined as [AnyObject]? - so you don't have to convert it to NSArray or NSMutableArray - just use it as is.

Since an array in swift is a value type, it is always copied by value and not by reference, which means a copy is created by just assigning to a variable. So in:

var sortingArray = fetchedResultsController?.fetchedObjects

a copy of fetchedObjects will be copied into sortingArray.

Upvotes: 3

Related Questions