MMMLoadableObserver

Objective-C

@interface MMMLoadableObserver : NSObject

Swift

class MMMLoadableObserver : NSObject

An proxy that sets itself as an observer of a loadable object and then forwards “did change” notifications to a block or a target/selector pair. This way your custom objects don’t have to conform to MMMLoadableObserver protocol exposing it in their public interfaces.

When initialized it adds itself as an observer of the given loadable and removes itself automatically when deallocated or when its remove method is called.

Both initializers return nil when the passed loadable is nil. This is handy when resubscribing to (possibile) different loadables many times and storing an instance of the observer in the same variable over and over: there is no need to check the target loadable and/or nullify the previous observer to unsubscribe.

  • Adds itself as an observer of the given loadable forwarding “did change” notifications to the given block.

    Returns nil when the passed loadable is nil as well. See also the docs on the class.

    Declaration

    Objective-C

    - (nullable id)initWithLoadable:(nullable id<MMMPureLoadable>)loadable
                              block:
                                  (nonnull MMMLoadableObserverDidChangeBlock)block;

    Swift

    init?(loadable: (any MMMPureLoadableProtocol)?, block: @escaping MMMLoadableObserverDidChangeBlock)
  • Adds itself as an observer of the given loadable forwarding “did change” notifications to the given target/selector.

    Returns nil when the passed loadable is nil as well. See also the docs on the class.

    Declaration

    Objective-C

    - (nullable id)initWithLoadable:(nullable id<MMMPureLoadable>)loadable
                             target:(nonnull id<NSObject>)target
                           selector:(nonnull SEL)selector;

    Swift

    init?(loadable: (any MMMPureLoadableProtocol)?, target: any NSObjectProtocol, selector: Selector)
  • Removes this observer from the associated loadable. It is safe to call it more than once. It’s also called automatically when the proxy is deallocated.

    Declaration

    Objective-C

    - (void)remove;

    Swift

    func remove()