Skip to content

Instantly share code, notes, and snippets.

@boolkybear
boolkybear / multilinesegmentedcontrol.swift
Created January 28, 2015 09:21
Multiline UISegmentedControl
extension UISegmentedControl
{
func makeMultiline(numberOfLines: Int)
{
for segment in self.subviews
{
let labels = segment.subviews.filter { $0 is UILabel } // [AnyObject]
labels.map { ($0 as UILabel).numberOfLines = numberOfLines }
}
}
@boolkybear
boolkybear / ifNotNil.swift
Last active August 29, 2015 14:14
Avoid if let ... pyramid of doom
func ifNotNil<T>(params: [T?], process: ([T])->Void)
{
let nilParams = params.filter { $0 == nil }
if countElements(nilParams) == 0
{
process(params.map { $0! })
}
}
func ifNotNil<T>(process: ([T])->Void, params:T?...)