I am trying to use the Swift equivalent of initWithContentsOfFile:
on an Array
. The documentation states that the equivalent is convenience init(contentsOfFile aPath: String!)
I have tried to call this with the following code:
var path = NSBundle.mainBundle().pathForResource("Standards", ofType: "plist")
var rawStandards = Array<Dictionary<String, AnyObject?>>(contentsOfFile: path)
The compiler is telling me, however, that it couldn't find an overload that accepts the supplied arguments. What am I missing?
@Leo Natan was really close, but the way that worked for me was:
var rawStandards = NSArray(contentsOfFile: path)
I was then able to access the elements:
for obj: AnyObject in rawStandards {
if var rawStandard = obj as? NSDictionary {
}
}
You are initializing a Swift array, not an NSArray
, which has the initWithContentsOfFile:
initializer method.
Try:
var rawStandards = NSArray(contentsOfFile: path) as Dictionary<String, AnyObject?>[]
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