2015/02/24

Initialize array in Swift

I saw this way to initialize array in Swift :
{
    var array = [] 
    array.append("Apple”) 
}
But next error appeared :

Error message : NSArray does not have a member named...

So I checked the type of this ‘array’ and Xcode showed its type is NSArray. Therefore I was not able to append any elements.

I should have declared its type like this :
{
    var array:[String] = []
    array.append("Apple”)
}
When you want to use NSMutableArray :
{
    var array:NSMutableArray = []
    array.addObject("Apple")
}



memo : Swift 1.1 , Xcode 6.1.1
Develop | Comments(0) | Trackback(0)
Comment

管理者のみに表示