Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
refactoring - use dot property accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
mackuba committed Oct 24, 2013
1 parent cbe86ab commit a8827ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
14 changes: 6 additions & 8 deletions Hive/Backend/BCClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ @interface BCClient ()
AFHTTPRequestOperation *_exchangeRateOperation;
}

@property (nonatomic) uint64 balance;

@end

@implementation BCClient
Expand Down Expand Up @@ -97,9 +99,7 @@ - (id)initWithBaseURL:(NSURL *)url

[[HIBitcoinManager defaultManager] start];

[self willChangeValueForKey:@"balance"];
_balance = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LastBalance"] unsignedLongLongValue];
[self didChangeValueForKey:@"balance"];
self.balance = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LastBalance"] unsignedLongLongValue];

[self updateNotifications];
}
Expand Down Expand Up @@ -167,11 +167,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
if ([keyPath compare:@"balance"] == NSOrderedSame)
{
dispatch_async(dispatch_get_main_queue(), ^{
[self willChangeValueForKey:@"balance"];
_balance = [HIBitcoinManager defaultManager].balance;
[self didChangeValueForKey:@"balance"];
self.balance = [HIBitcoinManager defaultManager].balance;

[[NSUserDefaults standardUserDefaults] setObject:@(_balance) forKey:@"LastBalance"];
[[NSUserDefaults standardUserDefaults] setObject:@(self.balance) forKey:@"LastBalance"];
});
}
else if ([keyPath compare:@"syncProgress"] == NSOrderedSame)
Expand Down Expand Up @@ -322,7 +320,7 @@ - (void)sendBitcoins:(uint64)amount
toHash:(NSString *)hash
completion:(void(^)(BOOL success, NSString *transactionId))completion
{
if (amount > _balance)
if (amount > self.balance)
{
completion(NO, nil);
}
Expand Down
26 changes: 13 additions & 13 deletions Hive/HIAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
return _persistentStoreCoordinator;
}

NSManagedObjectModel *mom = [self managedObjectModel];
NSManagedObjectModel *mom = self.managedObjectModel;
if (!mom) {
NSLog(@"%@:%@ No model to generate a store from", [self class], NSStringFromSelector(_cmd));
NSLog(@"%@:%@ No model to generate a store from", self.class, NSStringFromSelector(_cmd));
return nil;
}

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *applicationFilesDirectory = [self applicationFilesDirectory];
NSURL *applicationFilesDirectory = self.applicationFilesDirectory;
NSError *error = nil;

NSDictionary *properties = [applicationFilesDirectory resourceValuesForKeys:@[NSURLIsDirectoryKey] error:&error];
Expand Down Expand Up @@ -182,7 +182,7 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
// So - we need to delete old file
[[NSFileManager defaultManager] removeItemAtURL:url error:NULL];
return [self persistentStoreCoordinator];
return self.persistentStoreCoordinator;
}

_persistentStoreCoordinator = coordinator;
Expand All @@ -198,7 +198,7 @@ - (NSManagedObjectContext *)managedObjectContext
return _managedObjectContext;
}

NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
NSPersistentStoreCoordinator *coordinator = self.persistentStoreCoordinator;
if (!coordinator)
{
NSDictionary *dict = @{
Expand Down Expand Up @@ -245,7 +245,7 @@ - (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEv
// In this case, the manager returned is that of the managed object context for the application.
- (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window
{
return [[self managedObjectContext] undoManager];
return self.managedObjectContext.undoManager;
}

// Performs the save action for the application, which is to send the save: message to the application's
Expand All @@ -254,12 +254,12 @@ - (IBAction)saveAction:(id)sender
{
NSError *error = nil;

if (![[self managedObjectContext] commitEditing])
if (![self.managedObjectContext commitEditing])
{
NSLog(@"%@:%@ unable to commit editing before saving", [self class], NSStringFromSelector(_cmd));
NSLog(@"%@:%@ unable to commit editing before saving", self.class, NSStringFromSelector(_cmd));
}

if (![[self managedObjectContext] save:&error])
if (![self.managedObjectContext save:&error])
{
[NSApp presentError:error];
}
Expand All @@ -279,20 +279,20 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
return NSTerminateNow;
}

if (![[self managedObjectContext] commitEditing])
if (![self.managedObjectContext commitEditing])
{
NSLog(@"%@:%@ unable to commit editing to terminate", [self class], NSStringFromSelector(_cmd));
NSLog(@"%@:%@ unable to commit editing to terminate", self.class, NSStringFromSelector(_cmd));
return NSTerminateCancel;
}

if (![[self managedObjectContext] hasChanges])
if (!self.managedObjectContext.hasChanges)
{
return NSTerminateNow;
}

NSError *error = nil;

if (![[self managedObjectContext] save:&error])
if (![self.managedObjectContext save:&error])
{
// Customize this code block to include application-specific recovery steps.
BOOL result = [sender presentError:error];
Expand Down

0 comments on commit a8827ca

Please sign in to comment.