Skip to content
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-5489] Casting Objective-C id to Swift protocol type fails #48061

Closed
swift-ci opened this issue Jul 18, 2017 · 4 comments
Closed

[SR-5489] Casting Objective-C id to Swift protocol type fails #48061

swift-ci opened this issue Jul 18, 2017 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. runtime The Swift Runtime

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5489
Radar rdar://problem/33467916
Original Reporter SAJim (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9.0 beta 3, Swift 4.0

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, Runtime
Assignee None
Priority Medium

md5: 1ce388562651e8fee22b7ccf96a946a0

duplicates:

  • SR-3871 Protocol passing via objective-c / Any can't be cast back to protocol type

Issue Description:

A Swift struct assigned to an Objective-C id property (Any?) cannot be cast or compared to a Swift protocol type, and must first be cast back to its original type.

protocol AProtocol {
    var title: String {get}
}
struct AStruct: AProtocol {
    var title: String = ""
}

let value: Any? = AStruct()
value is AProtocol // == true

let dragItem = UIDragItem(itemProvider: NSItemProvider())
dragItem.localObject = AStruct() //localObject is of type Any?
dragItem.localObject is AProtocol // == false
dragItem.localObject as? AProtocol // == nil
dragItem.localObject as? AStruct is AProtocol // == true
dragItem.localObject as? AStruct as? AProtocol // != nil
@belkadan
Copy link
Contributor

@jckarter, do you have the dup for this?

@belkadan
Copy link
Contributor

@swift-ci create

@hamishknight
Copy link
Collaborator

@belkadan
Copy link
Contributor

Ah, that sounds right! Thanks, Hamish.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

3 participants