This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- load required modules | |
http = require("socket.http") --luasocket | |
ltn12 = require("ltn12") | |
mime = require("mime") | |
io = require("io") | |
json = require("json") -- luajson | |
-- Create a Lua table to represent our entity to save | |
--- This is from our doc REST example: http://docs.kinvey.com/rest-appdata.html | |
jamesBond = { ["firstName"] = "James", ["lastName"] = "Bond", ["email"] = "[email protected]", ["age"] = 34 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- GET back the object to verify that we saved it | |
response = {} | |
save = ltn12.sink.table(response) | |
id = objAsTable["_id"] -- get the _id field from the object table | |
url = "https://baas.kinvey.com/appdata/KINVEY_APP_ID/testObjects/" .. id | |
h = {Authorization = "Basic " .. (mime.b64("KINVEY_APP_ID:KINVEY_APP_SECRET")), ["Content-Type"] = "application/json" } | |
ok, code, headers = http.request{url = url, headers = h, sink = save, redirect = true, method = "GET"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (id) init | |
{ | |
if (self = [super init]) { | |
self.tableValues = [NSArray array]; | |
} | |
return self; | |
} | |
- (void) viewWillAppear:(BOOL)animated | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//books.h | |
@interface Book : NSObject <KCSPersistable> | |
@property (nonatomic) Author* author; | |
@property (nonatomic) NSString* title; | |
@end | |
//books.m | |
@implementation Book | |
+(NSDictionary *)kinveyPropertyToCollectionMapping { | |
return @{@"author" : @"authors"}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KCSCollection* books = [KCSCollection collectionFromString:@"books" ofClass:[Book class]]; | |
KCSLinkedAppdataStore* store = [KCSLinkedAppdataStore storeWithCollection:books options:nil]; | |
[store loadObjectWithId:@"HPBook6" withCompletionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil) { | |
Book* harryPotter = [objectsOrNil objectAtIndex:0]; | |
Author* jRowling = harryPotter.author; | |
} withProgressBlock:^(NSArray *objects, double percentComplete) { | |
//show progress | |
}]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define POLL_INTERVAL 0.05 //50ms | |
#define N_SEC_TO_POLL 1.0 //poll for 1s | |
#define MAX_POLL_COUNT N_SEC_TO_POLL / POLL_INTERVAL | |
- (void) testAnAsynchronousFunction | |
{ | |
__block BOOL done = NO; | |
//do async on a delay | |
float delayInSeconds = 0.5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define POLL_INTERVAL 0.05 //50ms | |
#define N_SEC_TO_POLL 1.0 //poll for 1s | |
#define MAX_POLL_COUNT N_SEC_TO_POLL / POLL_INTERVAL | |
#define CAT(x, y) x ## y | |
#define TOKCAT(x, y) CAT(x, y) | |
#define __pollCountVar TOKCAT(__pollCount,__LINE__) | |
#define POLL(__done) \ | |
NSUInteger __pollCountVar = 0; \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (UIImage*) imageWithColor:(UIColor*)color size:(CGSize)size | |
{ | |
UIGraphicsBeginImageContext(size); | |
UIBezierPath* rPath = [UIBezierPath bezierPathWithRect:CGRectMake(0., 0., size.width, size.height)]; | |
[color setFill]; | |
[rPath fill]; | |
UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (NSString* familyName in [UIFont familyNames]) { | |
NSLog(@"%@",[UIFont fontNamesForFamilyName:familyName]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if DEBUG | |
#define AssertLog(condition, desc, args...) NSAssert(condition, desc, ## args) | |
#define DBLog(format, args...) TFLog(@"%s, line %d: " format "\n", __func__, __LINE__, ## args); | |
#else | |
#define AssertLog(c, desc, args...) if (!(c)) TFLog(@"%s, line %d: " desc "\n", __func__, __LINE__, ## args); | |
#define DBLog(format, args...) do {} while(0) | |
#endif |
OlderNewer