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
  • see this stackoverflow.com/questions/30430550/… Commented Mar 24, 2017 at 12:42
  • 2
    It doesn't seem like creating an empty array is your only problem. I suggest you read some more about Swift. Commented Mar 24, 2017 at 12:44
  • But I was asking for Swift 3 Commented Apr 4, 2017 at 8:59

2 Answers 2

4

Like this: var someArray = [String]()

Sign up to request clarification or add additional context in comments.

Comments

0

I think this will do the trick

var myArray: NSArray! = []

1 Comment

Thank you, its only work in Swift3 Others or not working :) (y)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.