Skip to content

Instantly share code, notes, and snippets.

View johnhatvani's full-sized avatar

John Hatvani johnhatvani

View GitHub Profile
@johnhatvani
johnhatvani / Dates.playground
Last active March 15, 2023 10:12
Swift Playground #1 adding components to Date using operator overloading.
import Foundation
extension Int{
var day: (Int, Calendar.Component) {
return (self, .day)
}
var month: (Int, Calendar.Component) {
return (self, .month)
}
@johnhatvani
johnhatvani / NSObject+SimpleObjectMapping
Last active August 29, 2015 13:57
Simple Object Mapper. A category on NSObject that will construct a instance of your class and assign all values from the dictionary using KVC (make sure your property names are the same as the keys in the dictionary)
#import <objc/runtime.h>
@implementation NSObject (SimpleObjectMapping)
+ (instancetype) objectFromDictionary:(NSDictionary *)dictionary {
NSObject *instance = [[self.class alloc] init];
objc_property_t *properties = class_copyPropertyList(self.class, NULL);
objc_property_t property;