Skip to content

Instantly share code, notes, and snippets.

View sstadelman's full-sized avatar
🚀

Stan Stadelman sstadelman

🚀
View GitHub Profile
@sstadelman
sstadelman / odata API $filter.m
Created November 5, 2014 21:29
[offline] filtering entities from the database
-(void)fetchContactsWithCompletion:(void(^)(NSArray *entities))completion {
NSString *resourcePath = @"ContactCollection?$filter=length(company) gt 0 and length(function) gt 0";
[self scheduleRequestForResource:resourcePath withMode:SODataRequestModeRead withEntity:nil withCompletion:^(NSArray *entities, id<SODataRequestExecution> requestExecution, NSError *error) {
if (entities) {
completion(entities);
@sstadelman
sstadelman / programmatic filter.m
Created November 5, 2014 21:27
[online] filtering entities when $filter not supported by back end
-(void)fetchContactsWithCompletion:(void(^)(NSArray *entities))completion {
NSString *resourcePath = @"ContactCollection;
[self scheduleRequestForResource:resourcePath withMode:SODataRequestModeRead withEntity:nil withCompletion:^(NSArray *entities, id<SODataRequestExecution> requestExecution, NSError *error) {
if (entities) {
NSMutableArray *completeEntities = [[NSMutableArray alloc] init];
@sstadelman
sstadelman / StoreForRequestResourcePath.m
Last active August 29, 2015 14:06
StoreForRequestResourcePath
-(id<ODataStore>)storeForRequestToResourcePath:(NSString *)resourcePath
{
/*
First, test if mode is online- or offline-only anyway.
*/
if (self.workingMode == WorkingModeOnline) {
return self.networkStore;
} else if (self.workingMode == WorkingModeOffline) {
@sstadelman
sstadelman / DataController declaration.h
Created September 17, 2014 20:37
DataController.h declaration
#import "ODataStore.h"
#import "SODataStore.h"
#import "SODataStoreSync.h"
#import "SODataStoreAsync.h"
#import "Framework-Constants.h"
@interface DataController : NSObject
@property (nonatomic, assign) WorkingModes workingMode;
@sstadelman
sstadelman / createEntityInterface.m
Last active August 29, 2015 14:06
createEntityInterface
-(void)createEntity:(id<SODataEntity>) entity withCompletion:(void(^)(BOOL success))completion;
@sstadelman
sstadelman / ScheduleRequest with completionHandler.m
Last active August 29, 2015 14:06
ScheduleRequest with completionHandler
- (void) scheduleRequest:(id<SODataRequestParam>)request completionHandler:(void(^)(NSArray *entities, id<SODataRequestExecution>requestExecution, NSError *error))completion
NSString *finishedSubscription = [NSString stringWithFormat:@"%@.%@", kRequestDelegateFinished, request];
[[NSNotificationCenter defaultCenter] addObserverForName:finishedSubscription
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
id<SODataRequestExecution>requestExecution = note.object;
@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);
@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 / 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 / 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