(… and what’s the alternative)

“Chainlink swings at the playground” by Aaron Burden on Unsplash
  1. Reuse
    The first and most straightforward point is that once I’ve defined view styles in code (perhaps using composed functional view styling 😉), I can apply that same styling to any other views, without a tedious amount of copy and pasting; both within a project and across…


Photo by Samuel Zeller on Unsplash


“Positive bright white neon white sign on dark background, Museum of Fine Arts, Boston” by Lauren Peng on Unsplash


Photo by Steve Harvey on Unsplash


Photo by Bernd Viefhues on Unsplash


“Two "one-way" signs with arrows going different ways on a street in New York” by Brendan Church on Unsplash
  1. Line by line
let myBtn = UIButton()
myBtn.backgroundColor = .red
myBtn.frame = CGRect(x: 10, y: 10…


Photo by Fabrice Villard on Unsplash


Photo by Rob Potter on Unsplash
let view = UIView()
view.backgroundColor = .white
let viewOne = UIView()
viewOne.frame = CGRect(x: 30, y: 30, width: 30, height: 30)
viewOne.backgroundColor = .black
viewOne.alpha = 0.1
let viewTwo = UIView()
viewTwo.frame = CGRect(x: 120, y: 30, width: 30, height: 30)
viewTwo.backgroundColor = .black
viewTwo.alpha = 0.1
view.addSubview(viewOne)
view.addSubview(viewTwo)
UIView.animate(withDuration: 2.0, animations: {
viewOne.alpha = 1
viewOne.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)


Photo by rawpixel.com on Unsplash
enum Something 
{
case one
case two
case three
static func array(_ values: Something...) -> [Something]
{ return values }
}

Photo by Rick Mason on Unsplash
  1. Promises to Signals
import ReactiveKit
import PromiseKit
extension Promise
{
public func toSignal() -> Signal<T, NSError>
{
return Signal<T, NSError> { observer in
self.then { elem -> Void in
observer.completed(with: elem)
}.catch { error in
observer.failed(error as NSError)
}
return NonDisposable.instance
}
}
}

Andy Bennett

Veteran iOS developer, maker, hacker, builder, geek. http://github.com/akbsteam

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store