mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 17:32:17 +00:00
Restructured ModelChangeObserving a bit
This commit is contained in:
@@ -12,15 +12,27 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol MPModelChangeObserving <NSObject>
|
||||
|
||||
/* A class conforming to the protocoll will shoudl always fire the appropriate notifications listes below
|
||||
|
||||
You need to overwrite setValue:forKeyPath in a conforming class. For convinience you can just call the helper and lett it do the job
|
||||
|
||||
*/
|
||||
FOUNDATION_EXTERN NSString *const MPWillChangeModelNotification;
|
||||
FOUNDATION_EXTERN NSString *const MPDidChangreModelNotification;
|
||||
FOUNDATION_EXTERN NSString *const MPDidChangeModelNotification;
|
||||
|
||||
FOUNDATION_EXTERN NSString *const MPModelChangeObservingKeyPathKey;
|
||||
|
||||
@required
|
||||
- (void)observerModelChangesForKeyPath:(NSString *)keyPath;
|
||||
@end
|
||||
|
||||
- (void)willChangeModel;
|
||||
- (void)didChangeModel;
|
||||
/* Use this helper to fire the right notifications */
|
||||
@interface MPModelChangeObservingHelper : NSObject
|
||||
|
||||
+ (void)willChangeModelKeyPath:(NSString *)keyPath observer:(id<MPModelChangeObserving>)observer;
|
||||
+ (void)didChangeModelKeyPath:(NSString *)keyPath observer:(id<MPModelChangeObserving>)observer;
|
||||
|
||||
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath forTarget:(id)target;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPModelChangeObservingHelper.h"
|
||||
#import "MPModelChangeObserving.h"
|
||||
|
||||
NSString *const MPWillChangeModelNotification = @"com.hicknhack.macpass.MPWillChangeModelNotification";
|
||||
NSString *const MPDidChangreModelNotification = @"com.hicknhack.macpass.MPDidChangeModelNotification";
|
||||
NSString *const MPDidChangeModelNotification = @"com.hicknhack.macpass.MPDidChangeModelNotification";
|
||||
|
||||
NSString *const MPModelChangeObservingKeyPathKey = @"MPModelChangeObservingKeyPathKey";
|
||||
|
||||
@@ -21,8 +20,11 @@ NSString *const MPModelChangeObservingKeyPathKey = @"MPModelChangeObservingKeyPa
|
||||
}
|
||||
|
||||
+ (void)didChangeModelKeyPath:(NSString *)keyPath observer:(id<MPModelChangeObserving>)observer {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDidChangreModelNotification object:observer userInfo:@{ MPModelChangeObservingKeyPathKey : keyPath }];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDidChangeModelNotification object:observer userInfo:@{ MPModelChangeObservingKeyPathKey : keyPath }];
|
||||
}
|
||||
|
||||
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath forTarget:(id)target {
|
||||
[target setValue:value forKeyPath:keyPath];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,22 +0,0 @@
|
||||
//
|
||||
// MPModelChangeObserver.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 26/08/16.
|
||||
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/**
|
||||
* This class is usefull to implement modelchangeobserving by just forwarding the protocoll calls to the helper
|
||||
*/
|
||||
|
||||
@protocol MPModelChangeObserving;
|
||||
|
||||
@interface MPModelChangeObservingHelper : NSObject
|
||||
|
||||
+ (void)willChangeModelKeyPath:(NSString *)keyPath observer:(id<MPModelChangeObserving>)observer;
|
||||
+ (void)didChangeModelKeyPath:(NSString *)keyPath observer:(id<MPModelChangeObserving>)observer;
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user