Skip to content

Commit

Permalink
Added thread-safety
Browse files Browse the repository at this point in the history
Refactored core
  • Loading branch information
belkevich committed Sep 21, 2015
1 parent 9bda282 commit e516d2a
Show file tree
Hide file tree
Showing 33 changed files with 1,080 additions and 493 deletions.
186 changes: 154 additions & 32 deletions Example/Objective-C/AddressBook.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions Example/Objective-C/AddressBook/ListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,5 @@
#import <UIKit/UIKit.h>
#import "DTTableViewController.h"

@class APAddressBook;

@interface ListViewController : DTTableViewController
{
APAddressBook *addressBook;
}

@end
20 changes: 10 additions & 10 deletions Example/Objective-C/AddressBook/ListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@interface ListViewController ()
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activity;
@property (nonatomic, strong) APAddressBook *addressBook;
@end

@implementation ListViewController
Expand All @@ -24,9 +25,10 @@ - (id)initWithCoder:(NSCoder *)aDecoder
self = [super initWithCoder:aDecoder];
if (self)
{
addressBook = [[APAddressBook alloc] init];
self.addressBook = [[APAddressBook alloc] init];
__weak typeof(self) weakSelf = self;
[addressBook startObserveChangesWithCallback:^{
[self.addressBook startObserveChangesWithCallback:^
{
[weakSelf loadContacts];
}];
}
Expand Down Expand Up @@ -74,15 +76,15 @@ - (void)loadContacts
[self.memoryStorage removeAllTableItems];
[self.activity startAnimating];
__weak __typeof(self) weakSelf = self;
addressBook.fieldsMask = APContactFieldAll;
addressBook.sortDescriptors = @[
self.addressBook.fieldsMask = APContactFieldAll;
self.addressBook.sortDescriptors = @[
[NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES],
[NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES]];
addressBook.filterBlock = ^BOOL(APContact *contact)
self.addressBook.filterBlock = ^BOOL(APContact *contact)
{
return contact.phones.count > 0;
};
[addressBook loadContacts:^(NSArray *contacts, NSError *error)
[self.addressBook loadContacts:^(NSArray *contacts, NSError *error)
{
[weakSelf.activity stopAnimating];
if (!error)
Expand All @@ -91,10 +93,8 @@ - (void)loadContacts
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:error.localizedDescription
delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
Expand Down
189 changes: 0 additions & 189 deletions Pod/Core/APAddressBook.m

This file was deleted.

Loading

0 comments on commit e516d2a

Please sign in to comment.