Skip to content

Instantly share code, notes, and snippets.

View s4cha's full-sized avatar
🎯
Focusing

Sacha DSO s4cha

🎯
Focusing
View GitHub Profile
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Overide Back button everywhere.
UIImage *backButtonImage = [[UIImage imageNamed:@"backButton"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 3)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
return YES;
}
@s4cha
s4cha / rest1.swift
Last active October 25, 2015 14:41
let customer = Customer(identifier: 1234)
// We want to generate "/customers/1234"
protocol RestResource {
static func restName() -> String
func restId() -> String
}
func restURL<T:RestResource>(r:T) -> String {
return "/\(T.restName())/\(r.restId())"
}
extension Customer:RestResource {
static func restName() -> String {
return "customers"
}
func restId() -> String {
return "\(identifier)"
}
}
let customer = Customer(identifier: 1234)
restURL(customer) // -> "/customers/1234"
struct Customer {
var identifier:Int = 0
}
struct Product {
var identifier:Int = 0
}
struct Order {
var identifier:Int = 0
protocol Identifiable {
var identifier:Int {get}
}
struct Customer:Identifiable {
var identifier:Int = 0
}
struct Product:Identifiable {
var identifier:Int = 0
extension RestResource where Self:Identifiable {
func restId() -> String { return "\(identifier)" }
}
extension Customer:RestResource { static func restName() -> String { return "customers" } }
extension Product:RestResource { static func restName() -> String { return "products" } }
extension Order:RestResource { static func restName() -> String { return "orders" } }