Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Support NSArray KVO for elements - #2204

Merged
Allen Ballway (aballway) merged 3 commits into
microsoft:developfrom
aballway:kvo
Mar 23, 2017
Merged

Allen Ballway (aballway) merged 3 commits into
microsoft:developfrom
aballway:kvo

Conversation

@aballway

Copy link
Copy Markdown
Contributor

Causes an NSException to be thrown if addObserver:forKeyPath* or removeObserver:forKeyPath* are called on NSArray as per documentation.

Implements addObserver:toObjectsAndIndexes* and removeObserver:fromObjectsAtIndexes* for NSArray by calling addObserver and remvoeObserver on each specified element. Though documentation states that this method is not a simple convenience wrapper, we cannot do so because our current implementation of KVO cannot support a single observer intermediary for multiple observees without a larger refactor than this issue calls for.

Fixes #2068


#define NS_COLLECTION_THROW_ILLEGAL_KVO(KEYPATH) \
do { \
[NSException raise:NSInvalidArgumentException format:@"%@ is not supported. Key path: %@", NSStringFromSelector(_cmd), KEYPATH]; \

Choose a reason for hiding this comment

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

nit: no shouty KEYPATH.
Please add -[%hs %hs] with object_getClassName(self), sel_getName(_cmd); this will add the class (obvs.) and avoid the NSString intermediary for _cmd.


#include <Foundation/NSEnumerator.h>

#define NS_COLLECTION_THROW_ILLEGAL_KVO(KEYPATH) \

Choose a reason for hiding this comment

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

enumerator is an unusual header into which to put this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was looking for a shared internal place for the NS* classes where KVO is illegal. What's the reasonable place to stick this?

Choose a reason for hiding this comment

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

Reckon we could go with NSKeyValueObserving-Internal.h, but iunno.

@aballway

Copy link
Copy Markdown
Contributor Author

ping!

@aballway
Allen Ballway (aballway) merged commit dfe4387 into microsoft:develop Mar 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants