Your class or protocol, must be inherited (extended) by NSObject
or anyother class in its hierarchy, containing your code (function) with @objc
notation.
Example:
class TestClass {
public static func logIn(_ userId: String) -> User? { }
}
To use/declare @objc
with this function, class must extend NSObject
(or any other class in its hierarchy)
class TestClass {
@objc public static func logIn(_ userId: String) -> User? { }
}
Update:
struct
may not work with optional value in Objective-C, as a work around, you should change User
from struct
to class
Try following code and see:
public class User : NSObject {
// Your code
}
public final class Manager : NSObject {
@objc public static func logIn(_ userId: String) -> User? {
return nil
}
}
Here is snapshot with editor
class
declaration code for this function (class
for this function) – BoltenUser
– Bend