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

Add removeObserver:forKeyPath:context: to implementation #323

Merged
merged 9 commits into from
Sep 18, 2023

Conversation

gcasa
Copy link
Member

@gcasa gcasa commented Sep 13, 2023

Addresses issue #322.

Copy link
Contributor

@rfm rfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface looks fine.

I think we have two options for the implementation:

  1. raise an exception to say that the method is not yet implemented.
  2. implement the method to do what it's supposed to.

Implementing it as a synonym for -removeObjecter:forKeyPath: is IMO wrong since that would mean the app silently misbehaves.

@gcasa
Copy link
Member Author

gcasa commented Sep 14, 2023

The interface looks fine.

I think we have two options for the implementation:

  1. raise an exception to say that the method is not yet implemented.
  2. implement the method to do what it's supposed to.

Implementing it as a synonym for -removeObjecter:forKeyPath: is IMO wrong since that would mean the app silently misbehaves.

I am not sure what the proper implementation is. I don't know what should be done with the "context" parameter.

@rfm
Copy link
Contributor

rfm commented Sep 14, 2023

I'm not familaiar with it either, but it looks from the documentation as if -removeObjecter:forKeyPath: should remove all observers, but -removeObjecter:forKeyPath:context: should only remove the observer which was added using the specified context (an opaque pointer).

@gcasa
Copy link
Member Author

gcasa commented Sep 14, 2023

Since the context pointer is opaque I believe this is something that is left to the user to implement. I am going to do a bit more research on this. For now, I have made it so that the method throws an exception.

@triplef
Copy link
Member

triplef commented Sep 15, 2023

The context pointer is in fact not usable in GNUstep‘s current KVO implementation. I’ve opened #324 with some more details.

If you want to add this method you probably also want to add removeObserver:fromObjectsAtIndexes:forKeyPath:context:.

Copy link
Contributor

@rfm rfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks plausible to me. If only we had testcases :-(

@gcasa
Copy link
Member Author

gcasa commented Sep 18, 2023

That looks plausible to me. If only we had testcases :-(

I will add some as a separate PR. I will develop them on macOS.

@gcasa gcasa merged commit d97c84b into master Sep 18, 2023
9 checks passed
@gcasa gcasa deleted the NSKeyValueObserving_issue322 branch September 18, 2023 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants