Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@objc error when migrated to Swift 2

I had a Swift class declared like this:

@objc class MyHelper {
 // class code
}

I had to do this to access such class from Objective-C classes, since I'm mixing languages in my project. Now that I upgraded to Xcode 7, I get this error:

Only classes that inherit from NSObject can be declared @objc

And such class is not known by my Objective-C classes anymore. I guess that then I should inherit my Swift class from NSObject, will that have any impact in the way the app was working?

Thanks

like image 392
AppsDev Avatar asked Oct 19 '22 02:10

AppsDev


1 Answers

See the Apple staff SevenTenEleven's reply in the Apple Developer Forum.

He mentioned that this is because of @objc on Swift-rooted classes never quite behaved like an NSObject-rooted class, leading to various weirdness in the generated header and at runtime.

We can still treat any Swift class instance as an AnyObject, mark methods and properties on a Swift class as @objc, and conform to Objective-C protocols; the class just isn't exposed in the generated header and doesn't default to having its members available in Objective-C.

like image 118
Shamsudheen TK Avatar answered Nov 15 '22 02:11

Shamsudheen TK