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-5159] Warn when using KVO on a non-dynamic @objc property #47735

Closed
SlaunchaMan opened this issue Jun 8, 2017 · 0 comments
Closed

[SR-5159] Warn when using KVO on a non-dynamic @objc property #47735

SlaunchaMan opened this issue Jun 8, 2017 · 0 comments

Comments

@SlaunchaMan
Copy link
Contributor

Previous ID SR-5159
Radar None
Original Reporter @SlaunchaMan
Type Improvement
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s
Labels Improvement
Assignee None
Priority Medium

md5: 0e60bc79f1b873cdf0036caba5347770

duplicates:

  • SR-5115 KeyPath-based KVO: No diagnostic for inaccessible KVO KeyPaths

Issue Description:

Using the keypath-based KVO in Swift 4, you can write something like this:

class HelloThere: NSObject {
    
    @objc var value: String = ""
    
}

let object = HelloThere()

let observer = object.observe(\.value) { (object, change) in
    
    print("Changed to \(object.value)")
    
}

This will appear to be OK based on sample code, and will work for initial values, but the observer will not be called on future updates unless you add the “dynamic” modifier. Swift should warn the programmer of this case when a non-dynamic keypath is used.

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

No branches or pull requests

1 participant