Search code examples
iosswiftxcodensmutablearrayanyobject

could not cast value of type 'Swift._ContiguousArrayStorage<Swift.AnyObject>' to 'NSMutableArray'


I accidently updated iOS version in my phone from 10.3.3 to 11.0.3. Because of that I had to upgrade my xcode to latest 9.1 version. Now when I run my code in xcode 9.1 it appears

could not cast value of type 'Swift._ContiguousArrayStorage' to 'NSMutableArray'

It seems to be there is no longer conversion from 'AnyObject' array to 'NSMutableArray'. But I have used this conversion throughout my code. I have spend almost a day trying using [[String : AnyObject]] instead [AnyObject] which was not a good idea as it affects throughout the code and it feels like I'm doing my code again from the scratch. Can anyone please suggest a better solution.?


Solution

  • Solved it by using

    (MyAnyObjectArray! as NSArray).mutableCopy() as! NSMutableArray

    instead of

    MyAnyObjectArray as! NSMutableArray

    When I used xcode 8.3.3 and swift 3.2 use of .mutableCopy() was a error prone. But now it sees to be ok to use. Kind of confused. :(