I have an extension on String that defines test. I also want to be able to get test's functionality from NSString. In the real code String.test is more complex. So rather than re-implementing it for NSString I cast str to String and call test on it. My understanding here is that now str is of type String and String.test will be invoked, returning String Test.
However, it seems that str.test() winds up calling NSString.test and I wind up with unending recursion until the stack overflows.
import Foundation
extension NSString {
func test() -> NSString {
let str = self as String
return str.test() as NSString
}
}
extension String {
func test() -> String {
return "String test"
}
}
let s: NSString = "test"
s.test()
Change your first function to:
func test() -> NSString {
let str = self as String
return ("" + str.test()) as NSString
}
which should get you going...
then submit a bug report.
HTH
extension NSString {
func test() -> NSString {
let str = (self as String).test()
return str as NSString
}
}
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