Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to declare an Array in Swift

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 338
    Comment on it

    Hi Readers!

    There are different ways to declare Array in Swift. I will write few examples below:

    Example 1:

    let a : Array? = ["hello","hi"]
    

    Now in above example this is a constant array. You cannot add/append an element in it.

    Example 2: Below both versions of declaring array are same

    var a2 = Array<String>()
    var a3 = [String]()
    

    Example 3: This will declare an NSArray. Here you cannot add an element. And this array contains NSObjects.

    var a3 = ["hello",12]
    

    Example 4: This will declare a NSMutableArray. You can add elements in it similar to Objective c

     var a3 = [] as NSMutableArray
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: