You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can verify the problem with Swift 5.0 and 5.1 on the Apple Platform.
Additional Detail from JIRA
Votes
0
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: d0e96fae796e98c886ad4fc9cf2aed0a
duplicates:
SR-4827 Incorrect result resolving type for Obj-C block
Issue Description:
I've discovered an issue with @objc which I think is a bug. I've discussed the issue at the #swift-lang IRC channel before creating this issue. The situation is the following:
Create a Swift class and add the @objc attribute. Make sure to rename the class for use in Objective C - e.g. @objc(MKCBar)
Next use the class (e.g. `MKCBar`) in an Objective C file (e.g. `MKCFoo`) - like adding a property. In the header use forward declaration (@Class MKCBAR) and in the implementation file import the autogenerated Swift header file.
Add the Objective C file to the bridging header (MKCFoo.h) and thereby making it available to Swift
In another Swift file (Bas.swift) try to create an instance of the Objective C object and try to access the property which is defined using the forward declaration.
Sadly you can't!!!!
Remove the renaming from the @objc attribute and correct the forward declaration and import in the Objective C file.
Now you are able to use the property but lost the ability to rename the class
Environment
I can verify the problem with Swift 5.0 and 5.1 on the Apple Platform.
Additional Detail from JIRA
md5: d0e96fae796e98c886ad4fc9cf2aed0a
duplicates:
Issue Description:
I've discovered an issue with @objc which I think is a bug. I've discussed the issue at the #swift-lang IRC channel before creating this issue. The situation is the following:
Create a Swift class and add the @objc attribute. Make sure to rename the class for use in Objective C - e.g. @objc(MKCBar)
Next use the class (e.g. `MKCBar`) in an Objective C file (e.g. `MKCFoo`) - like adding a property. In the header use forward declaration (@Class MKCBAR) and in the implementation file import the autogenerated Swift header file.
Add the Objective C file to the bridging header (MKCFoo.h) and thereby making it available to Swift
In another Swift file (Bas.swift) try to create an instance of the Objective C object and try to access the property which is defined using the forward declaration.
Sadly you can't!!!!
Remove the renaming from the @objc attribute and correct the forward declaration and import in the Objective C file.
Now you are able to use the property but lost the ability to rename the class
I've attached a tiny sample project - please look at the Baz.swift file. Alternatively have a look at this blog post which also describes the problem: https://cjwirth.com/tech/circular-references-swift-objc
The text was updated successfully, but these errors were encountered: