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
Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Apple Swift version 4.2 (swiftlang-1000.0.36 clang-1000.10.44)
Additional Detail from JIRA
Votes
0
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: cc005abe69a65b2a9f6a9c3b53716373
duplicates:
SR-3871 Protocol passing via objective-c / Any can't be cast back to protocol type
Issue Description:
If I have a struct that conforms to a protocol and I pass it into Obj-C and get it back out again, I end up with a _SwiftValue stored in an Any. This by itself seems problematic, because it should only need the _SwiftValue wrapper when stored in an AnyObject, but casting back to the source type works. However, casting to a protocol breaks. If I first cast the value to AnyObject, then casting to a protocol works.
Example:
importFoundationprotocolFoo {
funcbar()
}
structMyStruct: Foo {
funcbar() {}
}
letary = NSMutableArray()
ary.add(MyStruct())
letx = ary.firstObject!
print(type(of: x)) // prints _SwiftValueprint(xisFoo) // prints falseprint(xasAnyObjectisFoo) // prints trueprint((xasAnyObject) asAnyisFoo) // prints false
The text was updated successfully, but these errors were encountered:
Environment
Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Apple Swift version 4.2 (swiftlang-1000.0.36 clang-1000.10.44)
Additional Detail from JIRA
md5: cc005abe69a65b2a9f6a9c3b53716373
duplicates:
Issue Description:
If I have a
struct
that conforms to a protocol and I pass it into Obj-C and get it back out again, I end up with a_SwiftValue
stored in anAny
. This by itself seems problematic, because it should only need the_SwiftValue
wrapper when stored in anAnyObject
, but casting back to the source type works. However, casting to a protocol breaks. If I first cast the value toAnyObject
, then casting to a protocol works.Example:
The text was updated successfully, but these errors were encountered: