Index: src/OFNotificationCenter.h ================================================================== --- src/OFNotificationCenter.h +++ src/OFNotificationCenter.h @@ -20,11 +20,10 @@ @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); #ifdef OF_HAVE_THREADS @class OFMutex; #endif -@class OFNotificationCenterHandle; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when a notification has been posted. * @@ -62,12 +61,12 @@ /** * @brief Adds an observer for the specified notification and object. * * @param observer The object that should receive notifications * @param selector The selector to call on the observer on notifications. The - * method must take exactly one object of type @ref - * OFNotification. + * method must take exactly one object of type + * @ref OFNotification. * @param name The name of the notification to observe * @param object The object that should be sending the notification, or `nil` * if the object should be ignored to determine what * notifications to deliver */ @@ -101,22 +100,21 @@ * if the object should be ignored to determine what * notifications to deliver * @param block The block to handle notifications * @return An opaque object to remove the observer again */ -- (OFNotificationCenterHandle *) - addObserverForName: (OFNotificationName)name - object: (nullable id)object - usingBlock: (OFNotificationCenterBlock)block; +- (id)addObserverForName: (OFNotificationName)name + object: (nullable id)object + usingBlock: (OFNotificationCenterBlock)block; /** * @brief Removes an observer. The specified observer must be one returned by * @ref addObserver:selector:name:object:. * * @param observer The object that was returned when adding the observer */ -- (void)removeObserver: (OFNotificationCenterHandle *)observer; +- (void)removeObserver: (id)observer; #endif /** * @brief Posts the specified notification. * Index: src/OFNotificationCenter.m ================================================================== --- src/OFNotificationCenter.m +++ src/OFNotificationCenter.m @@ -245,14 +245,13 @@ objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS -- (OFNotificationCenterHandle *) - addObserverForName: (OFNotificationName)name - object: (id)object - usingBlock: (OFNotificationCenterBlock)block +- (id)addObserverForName: (OFNotificationName)name + object: (id)object + usingBlock: (OFNotificationCenterBlock)block { void *pool = objc_autoreleasePoolPush(); OFNotificationCenterHandle *handle = [[[OFNotificationCenterHandle alloc] initWithName: name object: object @@ -267,13 +266,20 @@ return [handle autorelease]; } #endif -- (void)removeObserver: (OFNotificationCenterHandle *)handle +- (void)removeObserver: (id)handle_ { - void *pool = objc_autoreleasePoolPush(); + OFNotificationCenterHandle *handle; + void *pool; + + if (![handle_ isKindOfClass: [OFNotificationCenterHandle class]]) + @throw [OFInvalidArgumentException exception]; + + handle = handle_; + pool = objc_autoreleasePoolPush(); /* {} required to avoid -Wmisleading-indentation false positive. */ if (![handle isKindOfClass: [OFNotificationCenterHandle class]]) { @throw [OFInvalidArgumentException exception]; } Index: tests/OFNotificationCenterTests.m ================================================================== --- tests/OFNotificationCenterTests.m +++ tests/OFNotificationCenterTests.m @@ -107,11 +107,11 @@ test1->_received == 1 && test2->_received == 3 && test3->_received == 0 && test4->_received == 0) #ifdef OF_HAVE_BLOCKS __block bool received = false; - OFNotificationCenterHandle *handle; + id handle; notification = [OFNotification notificationWithName: notificationName object: self]; TEST(@"-[addObserverForName:object:usingBlock:]", (handle = [center addObserverForName: notificationName