-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebcc342
commit 56591ea
Showing
23 changed files
with
1,395 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
CVS | ||
.#* | ||
|
||
.hg | ||
.hgignore | ||
|
||
.svn | ||
|
||
bin | ||
Bin | ||
obj | ||
Debug | ||
Debug Dist | ||
Release | ||
Release Dist | ||
TestResults | ||
*.obj | ||
*.suo | ||
*.ncb | ||
*.aps | ||
*.user | ||
*.tli | ||
*.tlh | ||
*.idb | ||
*.pdb | ||
*.tlb | ||
*_i.h | ||
*_h.h | ||
*_i.c | ||
*_p.c | ||
*idl.h | ||
dlldata.c | ||
*ps.dll | ||
*ps.exp | ||
*ps.lib | ||
*.sdf | ||
*.opensdf | ||
ipch | ||
PrecompiledWeb | ||
|
||
build | ||
*.pbxuser | ||
*.perspectivev3 | ||
.DS_Store | ||
xcuserdata | ||
|
||
*.old | ||
*.log | ||
*.out | ||
*.cache | ||
*.orig | ||
logs | ||
|
||
gen | ||
.metadata | ||
|
||
*~ | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
KJSimpleBinding.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+39.2 KB
...g.xcodeproj/project.xcworkspace/xcuserdata/kdj.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// KJBindingManager.h | ||
// KJSimpleBinding | ||
// | ||
// Copyright (C) 2012 Kristopher Johnson | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
// Maintains a set of KVO observers, automatically copying values when they change | ||
|
||
@interface KJBindingManager : NSObject { | ||
@private | ||
NSMutableArray *_bindings; | ||
BOOL _isEnabled; | ||
} | ||
|
||
// Bind an observer's value specified by key path to a subject object's value. | ||
// | ||
// Neither observer nor subject are retained; it is the responsibility of the | ||
// caller to ensure that the objects are not deallocated for the duration | ||
// of the binding. | ||
// | ||
// The observer must be KVC-compliant for the observerKeyPath. | ||
// | ||
// The subject must be KVO-compliant for the subjectKeyPath | ||
- (void)bindObserver:(NSObject *)observer | ||
keyPath:(NSString *)observerKeyPath | ||
toSubject:(NSObject *)subject | ||
keyPath:(NSString *)subjectKeyPath; | ||
|
||
// Return YES if the binding manager is enabled; NO if not. | ||
// A binding manager is not enabled until its -enable method is called. | ||
- (BOOL)isEnabled; | ||
|
||
// Activate binding behavior. | ||
// This will immediately copy current values of subjects to the observers, and | ||
// changes will be propagated. | ||
- (void)enable; | ||
|
||
// Stop binding behavior. | ||
- (void)disable; | ||
|
||
// Clear list of bindings | ||
- (void)removeAllBindings; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// | ||
// KJBindingManager.m | ||
// KJSimpleBinding | ||
// | ||
// Copyright (C) 2012 Kristopher Johnson | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import "KJBindingManager.h" | ||
|
||
@interface KJBinding : NSObject | ||
|
||
@property (nonatomic, assign) NSObject *observer; | ||
@property (nonatomic, copy) NSString *observerKeyPath; | ||
@property (nonatomic, assign) NSObject *subject; | ||
@property (nonatomic, copy) NSString *subjectKeyPath; | ||
|
||
- (void)activate; | ||
|
||
- (void)deactivate; | ||
|
||
@end | ||
|
||
@implementation KJBinding | ||
|
||
@synthesize observer = _observer; | ||
@synthesize observerKeyPath = _observerKeyPath; | ||
@synthesize subject = _subject; | ||
@synthesize subjectKeyPath = _subjectKeyPath; | ||
|
||
- (void)dealloc { | ||
[_observerKeyPath release]; | ||
[_subjectKeyPath release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void)activate { | ||
[_subject addObserver:self | ||
forKeyPath:_subjectKeyPath | ||
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) | ||
context:NULL]; | ||
} | ||
|
||
- (void)deactivate { | ||
[_subject removeObserver:self forKeyPath:_subjectKeyPath]; | ||
} | ||
|
||
- (void)observeValueForKeyPath:(NSString *)keyPath | ||
ofObject:(id)object | ||
change:(NSDictionary *)change | ||
context:(void *)context | ||
{ | ||
id newValue = [change valueForKey:NSKeyValueChangeNewKey]; | ||
[_observer setValue:newValue forKeyPath:_observerKeyPath]; | ||
} | ||
|
||
@end | ||
|
||
|
||
@implementation KJBindingManager | ||
|
||
- (id)init { | ||
self = [super init]; | ||
if (self) { | ||
_bindings = [[NSMutableArray alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
if (_isEnabled) { | ||
// disconnect all the observers | ||
[self disable]; | ||
} | ||
[_bindings release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void)bindObserver:(NSObject *)observer | ||
keyPath:(NSString *)observerKeyPath | ||
toSubject:(NSObject *)subject | ||
keyPath:(NSString *)subjectKeyPath | ||
{ | ||
KJBinding *binding = [[KJBinding alloc] init]; | ||
binding.observer = observer; | ||
binding.observerKeyPath = observerKeyPath; | ||
binding.subject = subject; | ||
binding.subjectKeyPath = subjectKeyPath; | ||
[_bindings addObject:binding]; | ||
|
||
if (_isEnabled) { | ||
[binding activate]; | ||
} | ||
|
||
[binding release]; | ||
} | ||
|
||
- (void)enable { | ||
if (!_isEnabled) { | ||
for (KJBinding *binding in _bindings) { | ||
[binding activate]; | ||
} | ||
} | ||
else { | ||
NSLog(@"WARNING: KJBindingManger: attempted to enable already-enabled instance"); | ||
} | ||
_isEnabled = YES; | ||
} | ||
|
||
- (void)disable { | ||
if (_isEnabled) { | ||
for (KJBinding *binding in _bindings) { | ||
[binding deactivate]; | ||
} | ||
} | ||
else { | ||
NSLog(@"WARNING: KJBindingManger: attempted to disable already-disabled instance"); | ||
} | ||
_isEnabled = NO; | ||
} | ||
|
||
- (BOOL)isEnabled { | ||
return _isEnabled; | ||
} | ||
|
||
- (void)removeAllBindings { | ||
if (_isEnabled) { | ||
for (KJBinding *binding in _bindings) { | ||
[binding deactivate]; | ||
} | ||
} | ||
[_bindings removeAllObjects]; | ||
} | ||
|
||
@end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// AppDelegate.h | ||
// KJSimpleBindingDemo | ||
// | ||
// Created by Kristopher Johnson on 3/21/12. | ||
// Copyright (c) 2012 Capable Hands Technologies, Inc. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class ViewController; | ||
|
||
@interface AppDelegate : UIResponder <UIApplicationDelegate> | ||
|
||
@property (strong, nonatomic) UIWindow *window; | ||
|
||
@property (strong, nonatomic) ViewController *viewController; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// AppDelegate.m | ||
// KJSimpleBindingDemo | ||
// | ||
// Created by Kristopher Johnson on 3/21/12. | ||
// Copyright (c) 2012 Capable Hands Technologies, Inc. All rights reserved. | ||
// | ||
|
||
#import "AppDelegate.h" | ||
|
||
#import "ViewController.h" | ||
|
||
@implementation AppDelegate | ||
|
||
@synthesize window = _window; | ||
@synthesize viewController = _viewController; | ||
|
||
- (void)dealloc | ||
{ | ||
[_window release]; | ||
[_viewController release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | ||
{ | ||
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; | ||
// Override point for customization after application launch. | ||
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; | ||
self.window.rootViewController = self.viewController; | ||
[self.window makeKeyAndVisible]; | ||
return YES; | ||
} | ||
|
||
- (void)applicationWillResignActive:(UIApplication *)application | ||
{ | ||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | ||
} | ||
|
||
- (void)applicationDidEnterBackground:(UIApplication *)application | ||
{ | ||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | ||
} | ||
|
||
- (void)applicationWillEnterForeground:(UIApplication *)application | ||
{ | ||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. | ||
} | ||
|
||
- (void)applicationDidBecomeActive:(UIApplication *)application | ||
{ | ||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
} | ||
|
||
- (void)applicationWillTerminate:(UIApplication *)application | ||
{ | ||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. | ||
} | ||
|
||
@end |
Oops, something went wrong.