Skip to content

Commit

Permalink
Major improvements and additions to KVO helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkhatskevich committed Mar 30, 2015
1 parent 33005b0 commit ee11343
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 26 deletions.
8 changes: 8 additions & 0 deletions Example/ParseHelpers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
509FAADB1AB8D7EE002887E6 /* PFUser+ParseHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 509FAAD01AB8D7EE002887E6 /* PFUser+ParseHelpers.m */; };
509FAADC1AB8D7EE002887E6 /* PFUserExt.m in Sources */ = {isa = PBXBuildFile; fileRef = 509FAAD51AB8D7EE002887E6 /* PFUserExt.m */; };
50B482401AC8B02A00E01AFA /* PFObject+ParseHelpersKVO.m in Sources */ = {isa = PBXBuildFile; fileRef = 50B4823F1AC8B02A00E01AFA /* PFObject+ParseHelpersKVO.m */; };
50CF9A9A1AC999FB00801DC2 /* NSObject+ParseHelpersKVO.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF9A991AC999FB00801DC2 /* NSObject+ParseHelpersKVO.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -67,6 +68,9 @@
509FAAD51AB8D7EE002887E6 /* PFUserExt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFUserExt.m; sourceTree = "<group>"; };
50B4823E1AC8B02A00E01AFA /* PFObject+ParseHelpersKVO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PFObject+ParseHelpersKVO.h"; sourceTree = "<group>"; };
50B4823F1AC8B02A00E01AFA /* PFObject+ParseHelpersKVO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "PFObject+ParseHelpersKVO.m"; sourceTree = "<group>"; };
50CF9A981AC999FB00801DC2 /* NSObject+ParseHelpersKVO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+ParseHelpersKVO.h"; sourceTree = "<group>"; };
50CF9A991AC999FB00801DC2 /* NSObject+ParseHelpersKVO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+ParseHelpersKVO.m"; sourceTree = "<group>"; };
50CF9A9B1AC99D1800801DC2 /* ParseHelpersKVO.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ParseHelpersKVO.h; sourceTree = "<group>"; };
7A103900E2F1430F2773AE96 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
8941DE6007E80DA96F4EF5A5 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
E476E680D6FC49E2CAFD5515 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -197,8 +201,11 @@
50B4823D1AC8B02A00E01AFA /* KVO */ = {
isa = PBXGroup;
children = (
50CF9A9B1AC99D1800801DC2 /* ParseHelpersKVO.h */,
50B4823E1AC8B02A00E01AFA /* PFObject+ParseHelpersKVO.h */,
50B4823F1AC8B02A00E01AFA /* PFObject+ParseHelpersKVO.m */,
50CF9A981AC999FB00801DC2 /* NSObject+ParseHelpersKVO.h */,
50CF9A991AC999FB00801DC2 /* NSObject+ParseHelpersKVO.m */,
);
path = KVO;
sourceTree = "<group>";
Expand Down Expand Up @@ -361,6 +368,7 @@
509FAADB1AB8D7EE002887E6 /* PFUser+ParseHelpers.m in Sources */,
50528A071AB1C6CD00D6632E /* ViewController.m in Sources */,
509FAAD81AB8D7EE002887E6 /* NSObject+ParseHelpers.m in Sources */,
50CF9A9A1AC999FB00801DC2 /* NSObject+ParseHelpersKVO.m in Sources */,
50528A041AB1C6CD00D6632E /* AppDelegate.m in Sources */,
509FAADC1AB8D7EE002887E6 /* PFUserExt.m in Sources */,
509FAAD61AB8D7EE002887E6 /* NSArray+ParseHelpers.m in Sources */,
Expand Down
17 changes: 17 additions & 0 deletions Src/KVO/NSObject+ParseHelpersKVO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// NSObject+ParseHelpersKVO.h
// ParseHelpers
//
// Created by Maxim Khatskevich on 30/03/15.
// Copyright (c) 2015 Maxim Khatsevich. All rights reserved.
//

#import <Foundation/Foundation.h>

//===

@interface NSObject (ParseHelpersKVO)

- (void)observeParseObject:(id)targetObject withHandler:(void(^)(id object))changeHandler;

@end
45 changes: 45 additions & 0 deletions Src/KVO/NSObject+ParseHelpersKVO.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// NSObject+ParseHelpersKVO.m
// ParseHelpers
//
// Created by Maxim Khatskevich on 30/03/15.
// Copyright (c) 2015 Maxim Khatsevich. All rights reserved.
//

#import "NSObject+ParseHelpersKVO.h"

#import "NSObject+FBKVOController.h"
#import "MKHMacros.h"
#import "NSObject+MKHGenericHelpers.h"
#import <Parse/Parse.h>

//===

@implementation NSObject (ParseHelpersKVO)

- (void)observeParseObject:(id)targetObject withHandler:(void(^)(id object))changeHandler
{
if ([PFObject isClassOfObject:targetObject] && changeHandler)
{
PFObject *parseObject = (PFObject *)targetObject;

//===

[self.KVOController
observe:parseObject
keyPath:MKH_selectorStr(updatedAt)
options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew
block:^(id observer, id object, NSDictionary *change) {

if (parseObject.isDataAvailable)
{
dispatch_async(dispatch_get_main_queue(), ^{

changeHandler(parseObject);
});
}
}];
}
}

@end
8 changes: 1 addition & 7 deletions Src/KVO/PFObject+ParseHelpersKVO.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@

//===

// input param is "id", NOT "PFObject" to let developer
// to make input parameter of its custom PFObject-subclass
typedef void (^ParseHelpersKVOBlock)(id object);

//===

@interface PFObject (ParseHelpersKVO)

- (void)observeChanges:(ParseHelpersKVOBlock)changeHandler; // returns on Main queue!!!
- (void)observeChanges:(void(^)(id object))changeHandler; // returns on Main queue!!!

@end
41 changes: 22 additions & 19 deletions Src/KVO/PFObject+ParseHelpersKVO.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,29 @@

@implementation PFObject (ParseHelpersKVO)

- (void)observeChanges:(ParseHelpersKVOBlock)changeHandler
- (void)observeChanges:(void(^)(id object))changeHandler
{
MKH_weakSelfMacro;

//===

[self.KVOController
observe:self
keyPath:MKH_selectorStr(updatedAt)
options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew
block:^(id observer, id object, NSDictionary *change) {

if (weakSelf.isDataAvailable && changeHandler)
{
dispatch_async(dispatch_get_main_queue(), ^{

changeHandler(self);
});
}
}];
if (changeHandler)
{
MKH_weakSelfMacro;

//===

[self.KVOController
observe:self
keyPath:MKH_selectorStr(updatedAt)
options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew
block:^(id observer, id object, NSDictionary *change) {

if (weakSelf.isDataAvailable)
{
dispatch_async(dispatch_get_main_queue(), ^{

changeHandler(weakSelf);
});
}
}];
}
}

@end
14 changes: 14 additions & 0 deletions Src/KVO/ParseHelpersKVO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// ParseHelpersKVO.h
// ParseHelpers
//
// Created by Maxim Khatskevich on 30/03/15.
// Copyright (c) 2015 Maxim Khatsevich. All rights reserved.
//

#ifndef ParseHelpers_ParseHelpersKVO_h
#define ParseHelpers_ParseHelpersKVO_h



#endif

0 comments on commit ee11343

Please sign in to comment.