This file contains 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
@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; | |
} |
This file contains 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
let customer = Customer(identifier: 1234) | |
// We want to generate "/customers/1234" |
This file contains 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
protocol RestResource { | |
static func restName() -> String | |
func restId() -> String | |
} |
This file contains 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
func restURL<T:RestResource>(r:T) -> String { | |
return "/\(T.restName())/\(r.restId())" | |
} |
This file contains 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
extension Customer:RestResource { | |
static func restName() -> String { | |
return "customers" | |
} | |
func restId() -> String { | |
return "\(identifier)" | |
} | |
} |
This file contains 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
let customer = Customer(identifier: 1234) | |
restURL(customer) // -> "/customers/1234" |
This file contains 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
struct Customer { | |
var identifier:Int = 0 | |
} | |
struct Product { | |
var identifier:Int = 0 | |
} | |
struct Order { | |
var identifier:Int = 0 |
This file contains 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
protocol Identifiable { | |
var identifier:Int {get} | |
} | |
struct Customer:Identifiable { | |
var identifier:Int = 0 | |
} | |
struct Product:Identifiable { | |
var identifier:Int = 0 |
This file contains 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
extension RestResource where Self:Identifiable { | |
func restId() -> String { return "\(identifier)" } | |
} |
This file contains 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
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" } } |
OlderNewer