I'm working on a project in swift 3.0 where I have a tuple array to store set of data. Once I save them I convert this tuple array to a NSArray and I shuffle the elements (objects) in that array using another function. My requirement is to access elements in this retuned array (NSArray). My code as bellow(Please read the comments for better understand).
This is where I save data to my tuple array
var savedSongsArray:[(title:String,healerName:String,trackUrl:URL,imageUrl: String)] = []
func getAllTracksFromSavedPath(){
for i in 0 ..< trackIdsArray.count{
savedSongsArray.append((title: songDetailsArray[i].title , healerName:songDetailsArray[i].healerName, trackUrl: uRL, imageUrl: songDetailsArray[i].imageUrl))
//savedSongsArray is my tuple array
}
let arrayToBeShuffled = savedSongsArray as NSArray // This is where I convert it to a NSArray
}
My shuffle function
func shuffledSongsArray(array:NSArray) -> NSArray {
let mutableArray = array.mutableCopy() as! NSMutableArray
let count = mutableArray.count
if count>1 {
for i in ((0 + 1)...count-1).reversed(){
mutableArray.exchangeObject(at: i, withObjectAt: Int(arc4random_uniform(UInt32(i+1))))
}
}
return mutableArray as NSArray
}
Once I print the result of the mutableArray its as bellow
("indika - (index.jpeg)", "Steven Flemin", file:///Users/auxenta/Library/Developer/CoreSimulator/Devices/2B4EB1F8-FA38-4777-A274-10979F6EEB6F/data/Containers/Data/Application/CAB78797-8AB2-4DD9-8322-6F88B454BA74/Documents/5746821397741568.mp3, "https://storage.googleapis.com/feisty-beacon-159305.appspot.com/images.png")
how can I access individual elements in this tuple NSArray??