Created
January 23, 2016 00:17
-
-
Save alonecuzzo/16933d829b8325885852 to your computer and use it in GitHub Desktop.
Style with extensions
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
// | |
// ViewController.swift | |
// Styles | |
// | |
// Created by Jabari Bell on 1/22/16. | |
// Copyright © 2016 Jabari Bell. All rights reserved. | |
// | |
import UIKit | |
protocol BorderStyleable { | |
var borderWidth: CGFloat { get } | |
var borderColor: UIColor { get } | |
} | |
enum BorderStyle: BorderStyleable { | |
case Default | |
var borderWidth: CGFloat { | |
switch self { | |
case .Default: | |
return 1.0 | |
} | |
} | |
var borderColor: UIColor { | |
switch self { | |
case .Default: | |
return UIColor.redColor() | |
} | |
} | |
} | |
protocol BorderStyled { | |
var borderStyle: BorderStyle { get } | |
} | |
extension BorderStyled { | |
var borderStyle: BorderStyle { | |
return .Default | |
} | |
} | |
class MyView: UIView {} | |
extension MyView: BorderStyled { | |
} | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment