I'm pretty sure .count returns the length of an array but for some reason when I used it, it threw a weird error.
Heres my code:
let dataFile = NSBundle.mainBundle().pathForResource(RopeDataFile, ofType: nil)
let ropes = NSArray(contentsOfFile: dataFile!);
for i in 0..<ropes.count {
}
RopeDataFile is a constant of a property list that I made earlier.
For some reason it gives this error on ropes.count,
'NSArray?' does not have member named 'count'.
I'm new to swift and sorry if the problem is really simple.
NSArray(contentsOfFile: dataFile!) returns an optional array. So you have to use like
ropes?.count
Or you can unwrap the ropes array first
if let array = ropes{
for i in 0..< array.count {
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With