objective c - How to convert an NSArray from Obj-C to Array in Swift? -


yes, know title seems bit obvious, , can searched solution. know how convert 1-d nsarray array, simple enough.

however, not issue, nsarray different. please see following code

nsarray *artists;  artists = @[@"performed by: legendary group", @"performed by: ivan cheong",           @"performed by: tien nguyen", @"", @[@"performed by: dj happee              channel 3.3", @"performed by: adam cease", @""],              @"performed by: music between california , summer", @""]; 

then in cellforrowatindexpath, access so:

- (uitableviewcell *)tableview:(uitableview *)tableview     cellforrowatindexpath:(nsindexpath *)indexpath {     ...     if ( [ [artists[indexpath.section] objectatindex:indexpath.row]                  isequaltostring:@""] )     {         ....     } } 

as can see, nsarray contains array @ index 4. require trivial purposes.

i know possible convert nsarray swift standard array type?

i have tried implement equivalent:

var temp = nsarray()  let artists = ["performed by: legendary group", "performed by: ivan cheong",               "performed by: tien nguyen", "", ["performed by: dj happee          channel 3.3", "performed by: adam cease", ""], "performed by: music               between california , summer", ""]  temp = artists 

this works want, however, not swift 2.0's coding standards.

i want use array, don't know if possible?

thanks

create array of anyobjects:

let artists: [anyobject] = ["performed by: legendary group", "performed by: ivan cheong",     "performed by: tien nguyen", "", ["performed by: dj happee channel 3.3", "performed by: adam cease", ""], "performed by: music between california , summer", ""] 

then check type of each item in tableview function , handle accordingly:

 func tableview(tableview: uitableview!, cellforrowatindexpath indexpath: nsindexpath!) -> uitableviewcell {          switch artists.indexpath {         case string: //handle string         case nsarray: //handle array         default: //trap other stuff           }        } 

Comments