Reputation: 9120
I'm trying to implement the following code in an playground:
class File {
class func open(path: String, encoding: NSStringEncoding = NSUTF8StringEncoding) -> String? {
if NSFileManager().fileExistsAtPath(path) {
do {
return try String(contentsOfFile: path, encoding: encoding)
} catch let error as NSError {
print(error.code)
return nil
}
}
return nil
}
But when I try to access the class:
let read = File()
let content = read.open("ba")
I get this error: "Instance member "read" cannot be used on type custom type "File" "
Any of you knows why of this error or how can I fix it?
I would really appreciate your help.
Upvotes: 2
Views: 1099
Reputation: 575
You've defined a static method so its accessible like
let content = File.open("ba")
Upvotes: 2