Normally in C# I used to implement extension methods in a separate class (named 'ExtensionMethods') and used in the project.
Here in my first swift iphone App I need to implement some extension methods to 'String' class but providing me with this error
This works perfect with swift Playground but not sure how to use in a real project. really appreciate if someone can guide me with this. Thanks.
The extension must be at the root level - don't embed them into a class or whatever. So just write:
import UIKit
extension String {
var doubleValue: Double {
...
}
}
extension String {
func doubleValueT() -> Double {
...
}
}
Note that you can also combine them into a single extension:
import UIKit
extension String {
var doubleValue: Double {
...
}
func doubleValueT() -> Double {
...
}
}
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