New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-3332] @objc attribute on Linux platform leads to error #45920
Comments
Most of the time you don't need to write |
Can you share the code where this is an issue? Collecting examples might help us decide what to do about it. |
Here is the example codes: @objc(STWUser)
public class User: NSObject {
var jsonObject: [String:Any]
@objc public var id: Int64
@objc public var screenName: String
@objc public var name: String? {
return self.jsonObject["name"] as? String
}
@objc public var profileImageURL: URL? {
return URL(string: self.jsonObject["profile_image_url"] as? String ?? "")
}
init?(jsonObject: Any) {
guard let jsonObject = jsonObject as? [String:Any] else {
return nil
}
self.jsonObject = jsonObject
guard let id = jsonObject["id"] as? Int64 else {
return nil
}
self.id = id
guard let screenName = jsonObject["screen_name"] as? String else {
return nil
}
self.screenName = screenName
super.init()
}
} And I care the interface of obj-c line for working well with Obj-C. Meantime, without @objc, those codes are works well on Linux platform. I think @objc is only matters when Obj-C runtime is available. Isn't it? |
Why do you need to rename the class to STWUser in Objective-C? Is this a library that's intended to be used in both Objective-C and Swift? |
Yes. I want this library works well on both Obj-C, Swift. |
Comment by Joe Charlier (JIRA) I have a library that uses KVC and KVO that I'm trying to get working on Linux. This error is of course coming up on all String and Date properties. Is there anyway around this? Is KVC and KVO unavailable on linux swift? |
aepryus (JIRA User): KVO, KVC is the features of Obj-C's Foundation which is not implemented in Linux. I suggest these for who build the framework targeting Linux, macOS both. (Which I intend to make swift ignore `@objc` annotation on Linux. Not makes the error.) |
Comment by Joe Charlier (JIRA) @sinoru: I actually need the KVC functionality in this case, so simply ignoring the warning without getting String and Date working with KVC won't be very helpful in my case. |
I also came across this issue today. First of all, the error message is misleading. Given Apart from that, I need the attribute in a test where we also care about the runtime name of the class. The tested logic involves |
Hi. I came across the same case as described in this issue – sharing code for iOS app and Swift backend. I managed to clean #!/bin/bash
DIR=$(dirname "${BASH_SOURCE[0]}")
find "${DIR}/../Sources" -name '*.swift' | while read SWIFT_FILE
do
sed -i'' 's/@objc([^)]*)//g' "${SWIFT_FILE}"
sed -i'' 's/@objc//g' "${SWIFT_FILE}"
done |
Environment
Ubuntu 14.04.5 LTS, Linux Kernel 4.4.0-51-generic, Swift 3.0.1
Additional Detail from JIRA
md5: 8d8239631adbe9300b1172399e9d57fb
is duplicated by:
@objc
annotations to types that bridge to ObjC classesrelates to:
Issue Description:
I know that Objective-C Interoperability not works on linux. But I want to share the only the swift codes on Linux, macOS platforms.
I think it will be great if compiler ignore or just warning on @objc attribute on linux platform than print "only classes that inherit from NSObject can be declared @objc" error.
Thanks.
The text was updated successfully, but these errors were encountered: