Skip to content

Instantly share code, notes, and snippets.

@d-date
Created September 3, 2018 21:17
Show Gist options
  • Save d-date/28df56fb11eb72fa2493b4aae57adfd9 to your computer and use it in GitHub Desktop.
Save d-date/28df56fb11eb72fa2493b4aae57adfd9 to your computer and use it in GitHub Desktop.
Also, we can user function composition to UI implementation #CodePiece #tryswiftnyc
import UIKit
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
NSMutableParagraphStyle() |> (prop(\.alignment)) { _ in .center }
func set<Root, Value>(
_ kp: WritableKeyPath<Root, Value>,
_ value: Value
)
-> (Root) -> Root {
return (prop(kp)) { _ in value }
}
NSMutableParagraphStyle() |> set(\.alignment, .center)
let autolayoutStyle = set(\UIView.translatesAutoresizingMaskIntoConstraints, true)
UIView() |> autolayoutStyle
class MyViewController: UIViewController {
let subtitleLabel = UILabel()
|> set(\.font, .systemFont(ofSize: 17))
>>> set(\.textColor, UIColor.blue)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment