Skip to content

Instantly share code, notes, and snippets.

@seivan
Created January 29, 2014 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seivan/8696247 to your computer and use it in GitHub Desktop.
Save seivan/8696247 to your computer and use it in GitHub Desktop.
//Hmm lets not clear up the blocks because lol. ~ Seivan.
__block XXCurrentUser * user = nil;
dispatch_group_t groupRequestMyProfile = dispatch_group_create();
dispatch_group_t groupSaveMyProfile = dispatch_group_create();
dispatch_group_t groupRequestMyApplications = dispatch_group_create();
dispatch_group_t groupRequestMyNotifications = dispatch_group_create();
[[XXClient sharedManager] setObserverDidSignInBlock:^(XXAccessCredential *accessCredential, NSError *error) {
[[LUKeychainAccess standardKeychainAccess] setObject:accessCredential forKey:NSStringFromClass([self class])];
if(error)theBlock(nil,error);
else dispatch_group_leave(groupRequestMyProfile);
}];
dispatch_group_enter(groupRequestMyProfile);
dispatch_group_notify(groupRequestMyProfile, dispatch_get_main_queue(), ^{
[[XXClient sharedManager] requestMyProfile:^(NSDictionary *responseObject, NSError * error) {
if(error) theBlock(nil, error);
else {
user = [self objectFromResponseDictionary:responseObject];
dispatch_group_leave(groupSaveMyProfile);
}
}];
});
dispatch_group_enter(groupSaveMyProfile);
dispatch_group_notify(groupSaveMyProfile, dispatch_get_main_queue(), ^{
[[MagicalRecordStack defaultStack].context MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {
if(error) theBlock(nil,error);
else dispatch_group_leave(groupRequestMyApplications);
}];
});
dispatch_group_enter(groupRequestMyApplications);
dispatch_group_notify(groupRequestMyApplications, dispatch_get_main_queue(), ^{
[user requestGrantedApplicationsOnCompletionBlock:^(XXCurrentUser *currentUser, NSError *error) {
if(error) theBlock(nil,error);
else dispatch_group_leave(groupRequestMyNotifications);
}];
});
dispatch_group_enter(groupRequestMyNotifications);
dispatch_group_notify(groupRequestMyNotifications, dispatch_get_main_queue(), ^{
[user requestActionsOnCompletionBlock:^(XXCurrentUser *currentUser, NSError *error) {
if(error) theBlock(nil,error);
else theBlock(currentUser, error);
}];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment