Skip to content

Instantly share code, notes, and snippets.

@MariuszWisniewski
Last active November 23, 2015 01:00
Show Gist options
  • Save MariuszWisniewski/0d65f31b4cea38513ac4 to your computer and use it in GitHub Desktop.
Save MariuszWisniewski/0d65f31b4cea38513ac4 to your computer and use it in GitHub Desktop.
Item creation in Syncano
//following defined in SCConstants.h
typedef NS_ENUM(NSUInteger, SCDataObjectPermissionType) {
SCDataObjectPermissionTypeNone,
SCDataObjectPermissionTypeRead,
SCDataObjectPermissionTypeWrite,
SCDataObjectPermissionTypeFull,
};
// ...
// in the view contoller
- (void)createSomeObjects {
NSInteger some = 10;
for (int i = 0; i < some; ++i) {
Item *item = [[Item alloc] init];
item.item_name = [NSString stringWithFormat:@"Item nr %d",i];
item.item_number = @(i).stringValue;
item.item_price = @(i).stringValue;
item.qty_in_stock = @(i * 10).stringValue;
item.barcode = @"BARCODE";
// set the permissions on this item
item.owner_permissions = SCDataObjectPermissionTypeFull;
item.group_permissions = SCDataObjectPermissionTypeRead;
item.other_permissions = SCDataObjectPermissionTypeRead; // or SCDataObjectPermissionTypeNone if no one else should access this item
[item saveWithCompletionBlock:^(NSError *error) {
if (error) {
NSLog(@"Error saving object nr %d: %@", i, error);
}
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment