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

Swift project: Cannot remove an observer <CTAssetsPickerController 0x7f94862ad530> #139

Closed
DeepDiving2015 opened this issue Aug 26, 2015 · 9 comments
Labels

Comments

@DeepDiving2015
Copy link

hi,
I got this issue when use CTAssetsPickerController in my swift project:

Everything is ok when I open view and pick images. But when I back to the previous view without open CTAssetsPicker view, just crashed with:
*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <CTAssetsPickerController 0x7f94862ad530> for the key path "selectedAssets" from <CTAssetsPickerController 0x7f94862ad530> because it is not registered as an observer.'

please confirm following code:

  • (void)viewDidLoad
    {
    [super viewDidLoad];
    [self setupViews];
    [self setupEmptyViewController];
    [self checkAuthorizationStatus];
    [self addKeyValueObserver]; --->here to add
    }
  • (void)dealloc
    {
    [self removeKeyValueObserver]; ---> should remove in "viewWillDisapear" instead of here??
    }
@tomoyuki28jp
Copy link

I get the same error when I upgrade my project from xcode6.2 to xcode6.4 (swift1.2).

*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <CTAssetsPickerController 0x134240e40> for the key path "selectedAssets" from <CTAssetsPickerController 0x134240e40> because it is not registered as an observer.'

@tomoyuki28jp
Copy link

For quick fix, adding try-catch block prevents app to crash.
tomoyuki28jp@0540a7a

@1and2papa
Copy link
Owner

@tomoyuki28jp Thanks for your PR but I need time to review and hope to find a root cause of it first.

@tomoyuki28jp
Copy link

@chiunam Thanks for your reply. I haven't created a PR yet. If you need one, please let me know :)

@1and2papa
Copy link
Owner

Hi @DeepDiving2015 and @tomoyuki28jp, may I know if this problem is still exist in Xcode 7 GM? As I have no swift projects on hand, I cannot verify the issue and make subsequence changes.

Moving removeKeyValueObserver to viewWillDisappear does not look proper to me as I always put such adding/removing code in load/dealloc or appear/disappear pair.

@DeepDiving2015
Copy link
Author

@chiunam , I have not upgrade to Xcode 7 GM yet.
Temporarily, I add a flag to mark KeyValueObserver is added, and use it when remove.

@tomoyuki28jp
Copy link

@chiunam I confirm this problem still exists in iOS9 (Xcode7).

@1and2papa
Copy link
Owner

Hi @DeepDiving2015 & @tomoyuki28jp, this issue will be fixed in the next release.

@1and2papa 1and2papa added the bug label Sep 25, 2015
@tomoyuki28jp
Copy link

@chiunam Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants