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-8900] Cannot assign to a property through AnyObject #51406

Open
swift-ci opened this issue Oct 3, 2018 · 0 comments
Open

[SR-8900] Cannot assign to a property through AnyObject #51406

swift-ci opened this issue Oct 3, 2018 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 3, 2018

Previous ID SR-8900
Radar rdar://problem/15233922
Original Reporter pkamb (JIRA User)
Type Bug
Environment

Swift 4.2, Xcode 10

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

md5: fecd1beb40b55f31a3a7e32235cd1f19

relates to:

  • SR-5475 Can't set property declared optional in protocol

Issue Description:

Public bug for <rdar://problem/15233922> "Cannot assign to a property through AnyObject"

I'm attempting to implement NSOpenSavePanelDelegate in a Sandboxed Mac app.

The `sender: Any` parameter is a private system class that I cannot cast to. The private classes do not inherit from the public alternatives, so I cannot cast to those either.

I'm forced to use AnyObject. But doing so results in the error `Cannot assign to immutable expression`.

Sample Code:

extension PanelController: NSOpenSavePanelDelegate {
    
    func panel(_ sender: Any, didChangeToDirectoryURL url: URL?) {
        switch sender {
        case is NSSavePanel: () // false
        case is NSOpenPanel: () // false
        default:
            print("Sandboxed app. Uses private PowerBox open/save panel classes such as NSVBOpenPanel")
        }
        
        var panel = sender as AnyObject
        
        // Error: Cannot assign to immutable expression of type 'URL?'
        panel.directoryURL? = URL(fileURLWithPath: "/")!
    }

}

Also posted in the Swift Forums here:
https://forums.swift.org/t/anyobject-parameter-cannot-assign-to-immutable-expression/16642

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant