07-19-2023, 12:46 AM
In my case i had @objc protocol with optional methods and when i called its methods also in swift class i got that error, after removing the optional keyword from functions in the protocol the error was gone.
before (with error):
@objc protocol SomeDelegate:NSObjectProtocol{
optional func someDelegateMethod()
}
class MySwiftClass{
func notifyMyDelegate(){
mydelegate?.someDelegateMethod?() //this line caused the error
}
}
after:
@objc protocol SomeDelegate:NSObjectProtocol{
func someDelegateMethod()
}
class MySwiftClass{
func notifyMyDelegate(){
mydelegate?.someDelegateMethod()
}
}
before (with error):
@objc protocol SomeDelegate:NSObjectProtocol{
optional func someDelegateMethod()
}
class MySwiftClass{
func notifyMyDelegate(){
mydelegate?.someDelegateMethod?() //this line caused the error
}
}
after:
@objc protocol SomeDelegate:NSObjectProtocol{
func someDelegateMethod()
}
class MySwiftClass{
func notifyMyDelegate(){
mydelegate?.someDelegateMethod()
}
}