Reputation: 31955
I want to use NSArray
's arrayWithContentsOfFile
method in Swift since I have to create an Swift Array from the contents of a file, but how can I call it from within Swift code?
Since arrayWithContentsOfFile:
is a class method implemented in Objective-C's built-in NSArray
type, I cannot call it as called in this post, which calls an instance method by type-casting the Swift's Array
to Objective-C's NSArray
.
So is there any way to call the method, or any equivalent method like that?
Upvotes: 1
Views: 2765
Reputation: 2767
The method can be called in Swift like so:
NSArray(contentsOfFile: "PATH")
Using the method like so: NSArray.arrayWithContentsOfFile("PATH")
is deprecated.
This is a constructor, and should be used in the following manner:
var array = NSArray(contentsOfFile: "PATH")
Upvotes: 8