ios - Error: Deployment Update target 8.3 NSMutableArray and addObjectsFromArray - swift -


after updating xcode , device functions not running anymore. see it:

var jsonunico: nsmutablearray! = jsonresult["lista"] as? nsmutablearray self.tablelist.addobjectsfromarray(jsonunico) 

error: cannot invoke 'addobjectsfromarray' argument list of type '(nsmutablearray!)'

it working yesterday before upgrading

note: tablelist nsmutablearray

swift 1.2 no longer implicitly converts between nsarray , swift’s native array type – need explicitly cast 1 other. since addobjectsfromarray takes swift array, means need convert [anyobject].

normally you’d more helpful error message: error: 'nsmutablearray' not implicitly convertible '[anyobject]'; did mean use 'as' explicitly convert?, offer “fix-it”. looks isn’t happening because of use of implicitly-unwrapped optional nsmutablearray!.

but… isn’t such bad thing, since using implicitly-unwrapped optionals when fetching values out of dictionaries dangerous (if entry ever not there, app crash). alternative is:

if let jsonunico = jsonresult["lista"] as? nsmutablearray {     let tablelist = nsmutablearray()     // xcode recommend adding "as [anyobject]"     tablelist.addobjectsfromarray(jsonunico [anyobject])         } 

but since you’re doing as above it, may combine them:

if let jsonunico = jsonresult["lista"] as? [anyobject] {     tablelist.addobjectsfromarray(jsonunico) } 

Popular posts from this blog