Skip to content

Instantly share code, notes, and snippets.

View lifted-software's full-sized avatar

lifted-software

View GitHub Profile
{
"name": "Endeavor",
"abv": 8.9,
"brewery": "Saint Arnold",
"style": "ipa"
}
// Normal initialization
+ (instancetype)personWithName:(NSString *)name age:(NSInteger)age;
- (instancetype)initWithName:(NSString *)name age:(NSInteger)age;
- (instancetype)init;
// NSCopying protocol compliance
- (instancetype)copyWithZone:(NSZone *)zone;
- (instancetype)copy;
// NSCoding and NSSecureCoding protocol compliance
typedef NS_ENUM(NSInteger, BeerStyle) {
BeerStyleIpa,
BeerStyleStout,
BeerStyleKolsch
};
@interface Beer : NSObject <NSCopying, NSSecureCoding>
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *brewery;
NSDictionary *dict = [NSDictionary api_dictionaryWithJson:self.jsonBeer];
Beer *beer = [Beer beerWithDict:dict];
NSDictionary *dict = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:self.jsonBeer options:0 error:nil];
Beer *beer = [[Beer alloc] initWithDict:dict];
NSDate *date = [NSDate date];
NSData *data = [@"hello." dataUsingEncoding:NSUTF8StringEncoding];
DateAndData *dateAndData = [DateAndData dateAndDataWithIso_date:date
epoch_time:date
base64_data:data];
NSDictionary *jsonDict= [dateAndData toDict];
NSData *encodedJsonData = [jsonDict api_toJson];
NSLog(@"%@", [jsonDict api_jsonDescription]);
{
"isoDate" : "2017-07-05T22:53:41+00:00",
"base64Data" : "aGVsbG8u",
"epochTime" : 1499295221
}