Skip to content

Instantly share code, notes, and snippets.

@Bashta
Created August 18, 2015 10: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 Bashta/63430b4b28ee216383bf to your computer and use it in GitHub Desktop.
Save Bashta/63430b4b28ee216383bf to your computer and use it in GitHub Desktop.
PFObject *tempBill = [PFObject objectWithClassName:@"Bill"];
tempBill[@"amount"] = @0;
tempBill[@"category"] = @"";
tempBill[@"comment"] = pfBill[@"comment"];
tempBill[@"date"] = pfBill[@"date"];
tempBill[@"parentCategory"] = pfBill[@"parentCategory"];
tempBill[@"type"] = pfBill[@"type"];
[weakSelf saveBill:tempBill pfObjectWithRelations:pfObjectWithRelations completionBlock:^{
__weak __typeof(self) weakSelf = self;
[weakSelf saveBill:pfBill pfObjectWithRelations:tempBill completionBlock:nil];
}];
mmelnechuck [1:24 PM]
метод saveBil
mmelnechuck [1:24 PM]
- (void)saveBill:(PFObject *)pfBill pfObjectWithRelations:(PFObject *)pfObjectWithRelations completionBlock:(void (^)())completion
{
[pfBill saveEventually];
NSString *billsListKey;
if ([pfObjectWithRelations isKindOfClass:[PFUser class]])
billsListKey = @"BillsList";
else
billsListKey = @"SubBillsList";
NSMutableArray *billsList;
if (![pfObjectWithRelations objectForKey:billsListKey])
billsList = [[NSMutableArray alloc] init];
else
billsList = [pfObjectWithRelations objectForKey:billsListKey];
[billsList addObject:pfBill];
[pfObjectWithRelations setObject:billsList forKey:billsListKey];
[pfObjectWithRelations pinInBackgroundWithBlock:^(BOOL succeeded, NSError *PF_NULLABLE_S error){
[pfObjectWithRelations saveEventually];
if (completion)
completion();
}];
}
//падтяжка ліца
mmelnechuck [1:24 PM]
for (int i = 0; i < pfObjects.count; i++)
{
PFObject *currentPFBill = pfObjects[i];
Bill *bill = [[Bill alloc] initWithEntity:[NSEntityDescription entityForName:@"Bill" inManagedObjectContext:[[FBACoreDataHelper sharedManager] managedObjectContext]] insertIntoManagedObjectContext:[[FBACoreDataHelper sharedManager] managedObjectContext]];
bill.type = NILIFNULL(currentPFBill[@"type"]);
if(bill.type.intValue != self.type)
continue;
bill.amount = NILIFNULL(currentPFBill[@"amount"]);
bill.category = NILIFNULL(currentPFBill[@"category"]);
bill.comment = NILIFNULL(currentPFBill[@"comment"]);
bill.currency = NILIFNULL(currentPFBill[@"currency"]);
bill.date = NILIFNULL(currentPFBill[@"date"]);
bill.isHidden = NILIFNULL(currentPFBill[@"isHidden"]);
bill.parentCategory = NILIFNULL(currentPFBill[@"parentCategory"]);
NSArray *subBills = [currentPFBill objectForKey:@"SubBillsList"];
if (subBills.count)
bill.subcategories = [NSSet setWithArray:[self convertPFSubCategoriesToNSArray:subBills]];
[self.billsDataSource addObject:bill];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment