serddmit
(Serddmit)
1
Hello!
I found in the docs that:
You use the nonobjc
attribute to resolve circularity for bridging methods in a class marked with the objc
attribute
could help to resolve circularity. here
Could somebody help with an example of it?
Also nonobjc method could override objc method from here
Example:
public class P: NSObject {
@objc func test() {}
}
public class T: P {
@nonobjc override func test() {}
}
Thanks
serddmit
(Serddmit)
2
Could somebody help me with it please? Thank you!
michelf
(Michel Fortin)
3
You can't override an @objc
method with a @nonobjc
one. It's written in the documentation you linked to:
A method marked with the nonobjc
attribute can’t override a method marked with the objc
attribute.
You can do the reverse however (override a @nonobjc
method with an @objc
one). So this works:
public class P: NSObject {
@nonobjc func test() {}
}
public class T: P {
@objc override func test() {}
}
I'm not sure what kind of problem you're trying to solve here though.
Note that @nonobjc
is rarely needed since Swift 3 made it the default when it's not needed for an override or a protocol conformance.
1 Like
serddmit
(Serddmit)
4
There is a code snippet that shows that it's possible:
public class P: NSObject {
@objc func test() {}
}
public class T: P {
@nonobjc override func test() {}
}
Also I was checked the documentation for @nonobjc attribute and there was a statement for circular dependency that I didn't get.
michelf
(Michel Fortin)
5
You could file a bug report. The documentation says it's not possible. Either the compiler has a bug or the documentation is wrong.
I'm not sure either what is the meaning of "circularity" in this context.
1 Like
serddmit
(Serddmit)
6
Will do it, just need to confirm with other people that it's incorrect.
"Circularity" is other topic, it doesn't relate to override. Here I still need some answer.
Thank you
serddmit
(Serddmit)
7
Is anybody could suggest me about this two topics? Thanks!