Reputation: 1529
I have created an extension of String:
extension String {
var cSym:String? {
return CurrencyConversion.getCurrencySymbolWithCode(self)
}
}
When I go to use the extension I can see it and Xcode points to the extension fine, but then when I go to run I get and error stating:
Value of 'String' has no member 'cSym'
class func getCurrency(code : String) -> String {
return code.cSym ?? "$"
}
I have been looking at the Apple documentation https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Extensions.html and I can't see what the problem is. I have copied and pasted the code snippet from the documentation as well and I get the exact same error for the Double.
Maybe it's a Swift2.1 issue?
Upvotes: 3
Views: 893
Reputation: 1529
Found out the issue, Xcode seemed to have removed the targeting link to the one I was currently running from.
Not an ideal situation but if anyone comes across this, just double check Xcode hasn't removed the linkage for you.
Upvotes: 1
Reputation: 70110
If you're using your extension from a framework or in anything that's not in the same scope as the extension itself, you should mark its content with public
to make it available (Swift methods are internal
by default):
extension String {
public var cSym:String? {
return CurrencyConversion.getCurrencySymbolWithCode(self)
}
}
Upvotes: 0