Restructured ModelChangeObserving a bit

This commit is contained in:
michael starke
2016-08-28 14:32:18 +02:00
parent e9b9ca9425
commit 793176bf2d
4 changed files with 24 additions and 34 deletions

View File

@@ -195,7 +195,7 @@
4CAD748E15B88AC100104512 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAD748D15B88AC100104512 /* libz.dylib */; };
4CB915941A0159A20089CE5B /* DuplicateEntryOptionsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CB915931A0159A20089CE5B /* DuplicateEntryOptionsWindow.xib */; };
4CB9339916D3A0DD00A13B5D /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 4CB9339716D3A0DD00A13B5D /* Credits.rtf */; };
4CB9D77F1D70CE6B00F43F76 /* MPModelChangeObservingHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB9D77E1D70CE6B00F43F76 /* MPModelChangeObservingHelper.m */; };
4CB9D77F1D70CE6B00F43F76 /* MPModelChangeObserving.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB9D77E1D70CE6B00F43F76 /* MPModelChangeObserving.m */; };
4CB9D7821D71AFBE00F43F76 /* MPArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB9D7811D71AFBE00F43F76 /* MPArrayController.m */; };
4CBA2ABA17074C07006D8139 /* MPSettingsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CBA2AB917074C07006D8139 /* MPSettingsHelper.m */; };
4CC0D2CE17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC0D2CD17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m */; };
@@ -592,8 +592,7 @@
4CB915931A0159A20089CE5B /* DuplicateEntryOptionsWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DuplicateEntryOptionsWindow.xib; sourceTree = "<group>"; };
4CB9339816D3A0DD00A13B5D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = "<group>"; };
4CB9D77C1D70CBCE00F43F76 /* MPModelChangeObserving.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPModelChangeObserving.h; sourceTree = "<group>"; };
4CB9D77D1D70CE6B00F43F76 /* MPModelChangeObservingHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPModelChangeObservingHelper.h; sourceTree = "<group>"; };
4CB9D77E1D70CE6B00F43F76 /* MPModelChangeObservingHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPModelChangeObservingHelper.m; sourceTree = "<group>"; };
4CB9D77E1D70CE6B00F43F76 /* MPModelChangeObserving.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPModelChangeObserving.m; sourceTree = "<group>"; };
4CB9D7801D71AFBE00F43F76 /* MPArrayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPArrayController.h; sourceTree = "<group>"; };
4CB9D7811D71AFBE00F43F76 /* MPArrayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPArrayController.m; sourceTree = "<group>"; };
4CBA2AB617074B59006D8139 /* MPSettingsHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSettingsHelper.h; sourceTree = "<group>"; };
@@ -1307,6 +1306,7 @@
4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */,
4C2B0B7419F66F6400E48913 /* MPTargetNodeResolving.h */,
4CB9D77C1D70CBCE00F43F76 /* MPModelChangeObserving.h */,
4CB9D77E1D70CE6B00F43F76 /* MPModelChangeObserving.m */,
);
name = Protocolls;
sourceTree = "<group>";
@@ -1372,8 +1372,6 @@
4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */,
4CDE7B141D660983008C4160 /* MPObjectController.h */,
4CDE7B151D660983008C4160 /* MPObjectController.m */,
4CB9D77D1D70CE6B00F43F76 /* MPModelChangeObservingHelper.h */,
4CB9D77E1D70CE6B00F43F76 /* MPModelChangeObservingHelper.m */,
4CB9D7801D71AFBE00F43F76 /* MPArrayController.h */,
4CB9D7811D71AFBE00F43F76 /* MPArrayController.m */,
);
@@ -1718,7 +1716,7 @@
4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */,
4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */,
4C7B63761C0CB51F00D7038C /* TTTJSONTransformer.m in Sources */,
4CB9D77F1D70CE6B00F43F76 /* MPModelChangeObservingHelper.m in Sources */,
4CB9D77F1D70CE6B00F43F76 /* MPModelChangeObserving.m in Sources */,
4C77547516E55FE800970E02 /* MPInspectorViewController.m in Sources */,
4C89F524182FB4740069C73C /* MPAutotypeCommand.m in Sources */,
4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */,

View File

@@ -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

View File

@@ -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

View File

@@ -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