-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/mutualmobile/MMRecord int…
…o cnstoll_coreDataErrorHandling
- Loading branch information
Showing
45 changed files
with
2,928 additions
and
55 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
Examples/MMRecordAppDotNet/MMRecordAppDotNet.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
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
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
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
9 changes: 9 additions & 0 deletions
9
Examples/MMRecordAppDotNet/MMRecordAppDotNet/Vendor/FBTweak/FBTweak-Prefix.pch
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,9 @@ | ||
/** | ||
Copyright (c) 2014-present, Facebook, Inc. | ||
All rights reserved. | ||
|
||
This source code is licensed under the BSD-style license found in the | ||
LICENSE file in the root directory of this source tree. An additional grant | ||
of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
120 changes: 120 additions & 0 deletions
120
Examples/MMRecordAppDotNet/MMRecordAppDotNet/Vendor/FBTweak/FBTweak.h
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,120 @@ | ||
/** | ||
Copyright (c) 2014-present, Facebook, Inc. | ||
All rights reserved. | ||
This source code is licensed under the BSD-style license found in the | ||
LICENSE file in the root directory of this source tree. An additional grant | ||
of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@protocol FBTweakObserver; | ||
|
||
/** | ||
@abstract Represents a possible value of a tweak. | ||
@discussion Should be able to be persisted in user defaults, | ||
except actions (represented as blocks without a currentValue). | ||
For minimum and maximum values, should implement -compare:. | ||
*/ | ||
typedef id FBTweakValue; | ||
|
||
/** | ||
@abstract Represents a unique, named tweak. | ||
@discussion A tweak contains a persistent, editable value. | ||
*/ | ||
@interface FBTweak : NSObject <NSCoding> | ||
|
||
/** | ||
@abstract Creates a new tweak model. | ||
@discussion This is the designated initializer. | ||
*/ | ||
- (instancetype)initWithIdentifier:(NSString *)identifier; | ||
|
||
/** | ||
@abstract This tweak's unique identifier. | ||
@discussion Used when reading and writing the tweak's value. | ||
*/ | ||
@property (nonatomic, copy, readonly) NSString *identifier; | ||
|
||
/** | ||
@abstract The human-readable name of the tweak. | ||
@discussion Show the name when displaying the tweak. | ||
*/ | ||
@property (nonatomic, copy, readwrite) NSString *name; | ||
|
||
/** | ||
@abstract If this tweak is an action, with a block value. | ||
@param If YES, {@ref currentValue} should not be set and | ||
{@ref defaultValue} is a block rather than a value object. | ||
*/ | ||
@property (nonatomic, readonly, assign, getter = isAction) BOOL action; | ||
|
||
/** | ||
@abstract The default value of the tweak. | ||
@discussion Use this when the current value is unset. | ||
For actions, set this property to a block instead. | ||
*/ | ||
@property (nonatomic, strong, readwrite) FBTweakValue defaultValue; | ||
|
||
/** | ||
@abstract The current value of the tweak. Can be nil. | ||
@discussion Changes will be propagated to disk. Enforces minimum | ||
and maximum values when changed. Must not be set on actions. | ||
*/ | ||
@property (nonatomic, strong, readwrite) FBTweakValue currentValue; | ||
|
||
/** | ||
@abstract The minimum value of the tweak. | ||
@discussion Optional. If nil, there is no minimum. | ||
Should not be set on tweaks representing actions. | ||
*/ | ||
@property (nonatomic, strong, readwrite) FBTweakValue minimumValue; | ||
|
||
/** | ||
@abstract The maximum value of the tweak. | ||
@discussion Optional. If nil, there is no maximum. | ||
Should not be set on tweaks representing actions. | ||
*/ | ||
@property (nonatomic, strong, readwrite) FBTweakValue maximumValue; | ||
|
||
/** | ||
@abstract The step value of the tweak. | ||
@discussion Optional. If nil, the step value is calculated of miniumum and maxium. | ||
*/ | ||
@property (nonatomic, strong, readwrite) FBTweakValue stepValue; | ||
|
||
/** | ||
@abstract The decimal precision value of the tweak. | ||
@discussion Optional. If nil, the precision value is calculated of the step value. | ||
*/ | ||
@property (nonatomic, strong, readwrite) FBTweakValue precisionValue; | ||
|
||
/** | ||
@abstract Adds an observer to the tweak. | ||
@param object The observer. Must not be nil. | ||
@discussion A weak reference is taken on the observer. | ||
*/ | ||
- (void)addObserver:(id<FBTweakObserver>)observer; | ||
|
||
/** | ||
@abstract Removes an observer from the tweak. | ||
@param observer The observer to remove. Must not be nil. | ||
@discussion Optional, removing an observer isn't required. | ||
*/ | ||
- (void)removeObserver:(id<FBTweakObserver>)observer; | ||
|
||
@end | ||
|
||
/** | ||
@abstract Responds to updates when a tweak changes. | ||
*/ | ||
@protocol FBTweakObserver <NSObject> | ||
|
||
/** | ||
@abstract Called when a tweak's value changes. | ||
@param tweak The tweak which changed in value. | ||
*/ | ||
- (void)tweakDidChange:(FBTweak *)tweak; | ||
|
||
@end |
110 changes: 110 additions & 0 deletions
110
Examples/MMRecordAppDotNet/MMRecordAppDotNet/Vendor/FBTweak/FBTweak.m
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,110 @@ | ||
/** | ||
Copyright (c) 2014-present, Facebook, Inc. | ||
All rights reserved. | ||
This source code is licensed under the BSD-style license found in the | ||
LICENSE file in the root directory of this source tree. An additional grant | ||
of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import "FBTweak.h" | ||
|
||
@implementation FBTweak { | ||
NSHashTable *_observers; | ||
} | ||
|
||
- (instancetype)initWithCoder:(NSCoder *)coder | ||
{ | ||
NSString *identifier = [coder decodeObjectForKey:@"identifier"]; | ||
|
||
if ((self = [self initWithIdentifier:identifier])) { | ||
_name = [coder decodeObjectForKey:@"name"]; | ||
_defaultValue = [coder decodeObjectForKey:@"defaultValue"]; | ||
_minimumValue = [coder decodeObjectForKey:@"minimumValue"]; | ||
_maximumValue = [coder decodeObjectForKey:@"maximumValue"]; | ||
_precisionValue = [coder decodeObjectForKey:@"precisionValue"]; | ||
_stepValue = [coder decodeObjectForKey:@"stepValue"]; | ||
|
||
// Fall back to the user-defaults loaded value if current value isn't set. | ||
_currentValue = [coder decodeObjectForKey:@"currentValue"] ?: _currentValue; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (instancetype)initWithIdentifier:(NSString *)identifier | ||
{ | ||
if ((self = [super init])) { | ||
_identifier = identifier; | ||
_currentValue = [[NSUserDefaults standardUserDefaults] objectForKey:_identifier]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)encodeWithCoder:(NSCoder *)coder | ||
{ | ||
[coder encodeObject:_identifier forKey:@"identifier"]; | ||
[coder encodeObject:_name forKey:@"name"]; | ||
|
||
if (!self.isAction) { | ||
[coder encodeObject:_defaultValue forKey:@"defaultValue"]; | ||
[coder encodeObject:_minimumValue forKey:@"minimumValue"]; | ||
[coder encodeObject:_maximumValue forKey:@"maximumValue"]; | ||
[coder encodeObject:_currentValue forKey:@"currentValue"]; | ||
[coder encodeObject:_precisionValue forKey:@"precisionValue"]; | ||
[coder encodeObject:_stepValue forKey:@"stepValue"]; | ||
} | ||
} | ||
|
||
- (BOOL)isAction | ||
{ | ||
// NSBlock isn't a public class, walk the hierarchy for it. | ||
Class blockClass = [^{} class]; | ||
|
||
while ([blockClass superclass] != [NSObject class]) { | ||
blockClass = [blockClass superclass]; | ||
} | ||
|
||
return [_defaultValue isKindOfClass:blockClass]; | ||
} | ||
|
||
- (void)setCurrentValue:(FBTweakValue)currentValue | ||
{ | ||
NSAssert(!self.isAction, @"actions cannot have non-default values"); | ||
|
||
if (_minimumValue != nil && currentValue != nil && [_minimumValue compare:currentValue] == NSOrderedDescending) { | ||
currentValue = _minimumValue; | ||
} | ||
|
||
if (_maximumValue != nil && currentValue != nil && [_maximumValue compare:currentValue] == NSOrderedAscending) { | ||
currentValue = _maximumValue; | ||
} | ||
|
||
if (_currentValue != currentValue) { | ||
_currentValue = currentValue; | ||
[[NSUserDefaults standardUserDefaults] setObject:_currentValue forKey:_identifier]; | ||
|
||
for (id<FBTweakObserver> observer in [_observers setRepresentation]) { | ||
[observer tweakDidChange:self]; | ||
} | ||
} | ||
} | ||
|
||
- (void)addObserver:(id<FBTweakObserver>)observer | ||
{ | ||
if (_observers == nil) { | ||
_observers = [NSHashTable weakObjectsHashTable]; | ||
} | ||
|
||
NSAssert(observer != nil, @"observer is required"); | ||
[_observers addObject:observer]; | ||
} | ||
|
||
- (void)removeObserver:(id<FBTweakObserver>)observer | ||
{ | ||
NSAssert(observer != nil, @"observer is required"); | ||
[_observers removeObject:observer]; | ||
} | ||
|
||
@end |
53 changes: 53 additions & 0 deletions
53
Examples/MMRecordAppDotNet/MMRecordAppDotNet/Vendor/FBTweak/FBTweakCategory.h
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,53 @@ | ||
/** | ||
Copyright (c) 2014-present, Facebook, Inc. | ||
All rights reserved. | ||
This source code is licensed under the BSD-style license found in the | ||
LICENSE file in the root directory of this source tree. An additional grant | ||
of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class FBTweakCollection; | ||
|
||
/** | ||
@abstract A named grouping of collections. | ||
*/ | ||
@interface FBTweakCategory : NSObject <NSCoding> | ||
|
||
/** | ||
@abstract Creates a tweak category. | ||
@discussion This is the designated initializer. | ||
*/ | ||
- (instancetype)initWithName:(NSString *)name; | ||
|
||
/** | ||
@abstract The name of the category. | ||
*/ | ||
@property (nonatomic, copy, readonly) NSString *name; | ||
|
||
/** | ||
@abstract The collections contained in this category. | ||
*/ | ||
@property (nonatomic, copy, readonly) NSArray *tweakCollections; | ||
|
||
/** | ||
@abstract Fetches a collection by name. | ||
@param name The collection name to find. | ||
*/ | ||
- (FBTweakCollection *)tweakCollectionWithName:(NSString *)name; | ||
|
||
/** | ||
@abstract Adds a tweak collection to the category. | ||
@param tweakCollection The tweak collection to add. | ||
*/ | ||
- (void)addTweakCollection:(FBTweakCollection *)tweakCollection; | ||
|
||
/** | ||
@abstract Removes a tweak collection from the category. | ||
@param tweakCollection The tweak collection to remove. | ||
*/ | ||
- (void)removeTweakCollection:(FBTweakCollection *)tweakCollection; | ||
|
||
@end |
Oops, something went wrong.