Skip to content

Instantly share code, notes, and snippets.

View sstadelman's full-sized avatar
🚀

Stan Stadelman sstadelman

🚀
View GitHub Profile
@sstadelman
sstadelman / observeValueForKeyPath.m
Last active August 29, 2015 14:06
observeValuesForKeyPath
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (!object) return;
if ([keyPath isEqualToString:@"travelAgencies"]) {
NSLog(@"updated to x = %@", [[Model shared].travelAgencies description]);
[self.tableView reloadData];
}
}
@sstadelman
sstadelman / FetchRequestSample with completion block.m
Last active August 29, 2015 14:06
FetchRequestSample with completion block
-(void)fetchTravelAgenciesSampleWithCompletion:(void(^)(NSArray *entities))completion {
NSString *resourcePath = @"TravelagencyCollection";
[self scheduleRequestForResource:resourcePath withMode:SODataRequestModeRead withEntity:nil withCompletion:^(NSArray *entities, id<SODataRequestExecution> requestExecution, NSError *error) {
if (entities) {
completion(entities);
@sstadelman
sstadelman / Tracking unique id's.m
Last active August 29, 2015 14:06
Tracking unique id's
@interface MyViewController ()
@property (nonatomic, strong) NSString *accountRequestId;
@property (nonatomic, strong) NSString *opportunityRequestId;
//or
@property (nonatomic, strong) NSMutableArray *accountRequests;
@end
@sstadelman
sstadelman / Using options parameter for tag.m
Last active August 29, 2015 14:06
Using options parameter for tag
NSDictionary *myTagDictionary = @{@"tag":@"abcd1234"};
SODataRequestParamSingleDefault *request = requestExecution.request;
NSString *myTag = request.options[@"tag"];
@sstadelman
sstadelman / NSNotification subscribe for request notification.m
Last active August 29, 2015 14:06
NSNotification subscribe for request notification
- (void) loadModel
{
NSString *accountRequestNotificationIdentifier = @"AccountRequest";
[[NSNotificationCenter defaultCenter] addObserverForName:accountRequestNotificationIdentifier object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
//update the Accounts model
}];
@sstadelman
sstadelman / NSNotification post notification from request.m
Last active August 29, 2015 14:06
NSNotification post notification from request
- (void) requestServerResponse:(id<SODataRequestExecution>)requestExecution
{
if ([requestExecution.request.customTag isEqualToString:@"AccountRequest"]) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"AccountRequest" object:requestExecution];
}
}
@sstadelman
sstadelman / Custom Tags for requests.m
Last active August 29, 2015 14:06
Custom Tags for requests
- (void) loadModel
{
id<SODataRequestExecution> requestExecution1 = [myStore scheduleReadEntitySet:@"Accounts" delegate:self options:nil];
requestExecution1.request.customTag = @"AccountRequest";
id<SODataRequestExecution> requestExecution2 = [myStore scheduleReadEntitySet:@"Opportunities" delegate:self options:nil];
requestExecution2.request.customTag = @"OpportunityRequest";
}
- (void) requestServerResponse:(id<SODataRequestExecution>)requestExecution
@sstadelman
sstadelman / Parse server response.m
Last active August 29, 2015 14:06
Parse server response
- (void) requestServerResponse:(id<SODataRequestExecution>)requestExecution
{
id<SODataRequestExecution>requestExecution = note.object;
id<SODataResponse> response = requestExecution.response;
id<SODataResponseSingle> respSingle = (id<SODataResponseSingle>) response;
id<SODataPayload> p = respSingle.payload;
SODataEntitySetDefault *entities = (id<SODataEntitySet>)p;
if ([requestExecution.request.customTag isEqualToString:@"AccountRequest"]) {
@sstadelman
sstadelman / Example with block createEntity.m
Last active August 29, 2015 14:06
Example with block createEntity
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ReturnInputFromAdd"]) {
self.properties = [NSMutableArray array];
prop = [[SODataPropertyDefault alloc] initWithName:@"NAME"];
prop.value = self.nameInput.text;
[self.properties addObject:prop];
prop = [[SODataPropertyDefault alloc] initWithName:@"URL"];
prop.value = self.urlInput.text;
@sstadelman
sstadelman / fetchTravelAgenciesSampleWithCompletion.m
Last active August 29, 2015 14:06
fetchTravelAgenciesSampleWithCompletion
-(void)fetchTravelAgenciesSampleWithCompletion:(void(^)(NSArray *entities))completion {
NSString *resourcePath = @"TravelagencyCollection";
SODataRequestParamSingleDefault *myRequest = [[SODataRequestParamSingleDefault alloc] initWithMode:mode resourcePath:resourcePath];
myRequest.payload = entity ? entity : nil;
[self scheduleRequest:myRequest completionHandler:^(NSArray *entities, id<SODataRequestExecution> requestExecution, NSError *error) {
if (entities) {
completion(entities);