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
class ViewController: UIViewController { | |
var customizerObject: SpecialProtocol? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
specialMethod() | |
} |
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
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
specialMethod() | |
} | |
func specialMethod() { | |
// overridable method |
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 UIBarButtonItem { | |
public func programmaticallyTap() { | |
if let target = target | |
, let action = action | |
{ | |
target.value(forKey: NSStringFromSelector(action)) | |
} | |
} | |
} |
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 ==(lhs: EnumString, rhs: String) -> Bool { | |
return lhs.isEqual(rhs) | |
} | |
func ==(lhs: String, rhs: EnumString) -> Bool { | |
return rhs.isEqual(lhs) | |
} | |
class EnumString: NSObject { | |
let rawValue: 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
enum ErrorEnum: Error { | |
case FooError | |
case BarError | |
} | |
func bar(success: Bool) throws -> String { | |
if success { | |
return "bar success" | |
} | |
throw ErrorEnum.BarError |
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
// 1 | |
public struct SwiftyNotificationCenter {} | |
// ... | |
// extended somewhere else in your code base | |
// 2 | |
extension SwiftyNotificationCenter { | |
static var buttonNotification = SwiftyNotification<String, String, Int>() | |
static var anotherNotification = SwiftyNotification<String, UIColor, Bool>() |
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
// 1 | |
var buttonNotification = SwiftyNotification<String, String, Int>() | |
// 2 | |
buttonNotification.add(subscriber: self) { (info, n) in | |
// 3 | |
print(info) | |
// 4 | |
n = 8 | |
} |
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
// DHConstraintBuilder | |
//1 | |
view_cb.addConstraints(() |-^ greenView_cb ^-^ 15.5 ^-^ redView_cb ^-| ()).H | |
//2 | |
view_cb.addConstraints(() |-^ blueView_cb ^-| ()).H | |
//3 | |
view_cb.addConstraints(() |-^ greenView_cb ^-^ blueView_cb ^-| ()).V |
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
// NSLayoutConstraint | |
// Given an array of 3 views | |
let viewArray = [ | |
greenView_vf, | |
redView_vf, | |
blueView_vf | |
] | |
// set this value to false to make auto layout work | |
viewArray.forEach({ $0.translatesAutoresizingMaskIntoConstraints = false }) |
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
// Adding a vertical constraint between view1 and view2 using default padding | |
// DHConstraintBuilder | |
parentView.addConstraints(view1 ^-^ view2).V | |
// NSLayoutConstraints | |
parentView.translatesAutoresizingMaskIntoConstraints = false | |
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[view1]-[view2]" | |
, options: NSLayoutFormatOptions(rawValue: 0) | |
, metrics: nil, views: ["view1": view1, "view2": view2])) |