Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mutualmobile/MMRecord int…
Browse files Browse the repository at this point in the history
…o cnstoll_swift
  • Loading branch information
cnstoll committed Jun 25, 2014
2 parents 86280e3 + 634a11a commit df69a06
Show file tree
Hide file tree
Showing 43 changed files with 2,906 additions and 55 deletions.
100 changes: 100 additions & 0 deletions Examples/MMRecordAppDotNet/MMRecordAppDotNet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
#import "ADNPostManager.h"
#import "Counts.h"

@interface ADNPostsViewController ()
#import "FBTweakViewController.h"
#import "FBTweakStore.h"

@interface ADNPostsViewController () <FBTweakViewControllerDelegate>

@property (nonatomic, strong) ADNPostManager *postManager;
@property (nonatomic, copy) NSArray *posts;
Expand All @@ -38,8 +41,20 @@ - (void)viewDidLoad {
forCellReuseIdentifier:@"PostCell"];

[self getPosts];

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"Tweaks" style:UIBarButtonItemStyleBordered target:self action:@selector(showTweaks)];
self.navigationItem.rightBarButtonItem = item;
}

- (void)showTweaks {
FBTweakViewController *viewController = [[FBTweakViewController alloc] initWithStore:[FBTweakStore sharedInstance]];
viewController.tweaksDelegate = self;
[self presentViewController:viewController animated:YES completion:NULL];
}

- (void)tweakViewControllerPressedDone:(FBTweakViewController *)tweakViewController {
[self dismissViewControllerAnimated:YES completion:NULL];
}

#pragma mark - Posts Request Methods

Expand Down
13 changes: 9 additions & 4 deletions Examples/MMRecordAppDotNet/MMRecordAppDotNet/MMAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
#import "ADNRecord.h"
#import "ADNServer.h"
#import "MMJSONServer.h"
#import "MMDataManager.h"
#import "FBMMRecordTweakModel.h"

@implementation MMAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[ADNServer registerAFHTTPClient:[ADNHTTPClient sharedClient]];
[ADNRecord registerServerClass:[ADNServer class]];
//[ADNServer registerAFHTTPClient:[ADNHTTPClient sharedClient]];
//[ADNRecord registerServerClass:[ADNServer class]];

//[MMJSONServer registerResourceName:@"posts" forPathComponent:@"posts"];
//[ADNRecord registerServerClass:[MMJSONServer class]];
[FBMMRecordTweakModel loadTweaksForManagedObjectModel:[MMDataManager sharedDataManager].managedObjectModel];
#define FBMMRecordTweakModelDefine

[MMJSONServer registerResourceName:@"posts" forPathComponent:@"posts"];
[ADNRecord registerServerClass:[MMJSONServer class]];

//[MMRecord setLoggingLevel:MMRecordLoggingLevelDebug];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "FBMMRecordTweakModel.h"
#endif

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 Examples/MMRecordAppDotNet/MMRecordAppDotNet/Vendor/FBTweak/FBTweak.h
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 Examples/MMRecordAppDotNet/MMRecordAppDotNet/Vendor/FBTweak/FBTweak.m
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
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
Loading

0 comments on commit df69a06

Please sign in to comment.