I want to add a class function to the extension:
extension String { class func test () { } }
I get an error: Class methods are only allowed within classes; use 'static' to declare a static method Class methods are only allowed within classes; use 'static' to declare a static method
Or how can I call " String.test() "
But for NSString
extension NSString { class func aaa () { } }
no mistakes.
If I add a static keyword:
extension String { static func aaa () { self.stringByAppendingString("Hello") } }
Got: Expression resolves to an unused function ,
So, as I have to add a class function, I also want to use the self. method self. .
EDIT: It works!
extension String { static func aaa (path:String) -> String { return path.stringByAppendingString("Hello") } }
but about @lan answer:
mutating func bbb(path: String) { self += "world" }
When I type, it looks like this:
String.bbb(&<
source share