Swift - How to convert a swift array to NSArray?

Viewed 11200

I have the following class

class Game {
// An array of player objects
    private var playerList: [Player]?
}

I want to enumerate through the playerList; this requires to import Foundation then cast it to a NSArray; but its always complaining that it can't convert it

 func hasAchievedGoal() {
        if let list:NSArray = playerList {

        }

        for (index,element) in list.enumerate() {
            print("Item \(index): \(element)")
        }
   }

Errors:

Cannot convert value of type '[Player]?' to specified type 'NSArray?'

I've tried:

if let list:NSArray = playerList as NSArray

What am i doing wrong?

Thanks

2 Answers
Related