1

How to create Empty array in swift when I am creating by this

var myArray: NSArray!

I am getting error when I am accessing

myArray.count 

it's giving an error

fatal error: unexpectedly found nil while unwrapping an Optional value

and exc_bad_instruction (code=exc_i386_invop subcode=0x0)

Then how to reslove this issue?

3

2 Answers 2

4

Like this: var someArray = [String]()

0

I think this will do the trick

var myArray: NSArray! = []
1
  • Thank you, its only work in Swift3 Others or not working :) (y)
    – Anup Gupta
    Mar 24, 2017 at 13:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.