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-5523] After UIKit uses, the object is not conforming to any protocol #48095

Closed
swift-ci opened this issue Jul 21, 2017 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5523
Radar None
Original Reporter dalu93 (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode Version 8.3.2 (8E2002)

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

md5: a50249dc71b60ab4d535b34b59da4998

duplicates:

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

Issue Description:

I found out a very strange issue which is happening when calling the `performSegue` method in UIKit

I have a structure like following

protocol MyProtocol {}

struct MyStruct: MyProtocol {}

By passing the structure as sender in the performSegue like following
`vc.performSegue(withIdentifier: "id", sender: myStructInstance)`

In the `preparForSegue` method, the sender instance cannot be converted to `MyProtocol`

sender! is MyProtocol // return false
sender as! MyProtocol // crashes
sender! is MyStruct // return true
sender as! MyStruct // return true

I fixed this problem by wrapping `MyProtocol` inside an another structure and then I can easily access the value as below

struct Wrapper {
    let myProtocol: MyProtocol
}

(sender as! Wrapper).myProtocol is MyProtocol // return true
@swift-ci
Copy link
Collaborator Author

Comment by James Froggatt (JIRA)

related: https://bugs.swift.org/browse/SR-5489

@belkadan
Copy link
Contributor

Yeah, it's the same issue.

@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.
Projects
None yet
Development

No branches or pull requests

2 participants