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
#import <UIKit/UIKit.h> | |
// IB_DESIGNABLE means that the view will be | |
// rendered live in Interface Builder. | |
IB_DESIGNABLE | |
@interface MJPlaceholderView : UIView | |
// IBInspectable means that the property |
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
let values: [UInt] = [4, 8, 15, 16, 23, 42] | |
let biggestValue = values.reduce(0, {$1 > $0 ? $1 : $0}) | |
// biggestValue is now 42 |
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
let values = [4, 8, 15, 16, 23, 42] | |
let meanValue = values.reduce(0, +) / values.count | |
// + is a operator function and we can pass it in to reduce as the function parameter. |
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
operator infix <=> {} | |
infix func <=> <T>(inout left: T, inout right: T) { | |
let tmp = left | |
left = right | |
right = tmp | |
} | |
var a = 1337 | |
var b = 4711 |
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
operator postfix ** {} | |
postfix func ** (value: Int) -> Int { | |
return value * value | |
} | |
let a = 3** + 1 | |
// a now contains 10 |
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
operator infix <- {} | |
infix func <- <T>(inout left: T, right: T) { | |
left = right | |
} | |
var value = 0 // Initialize | |
value <- 1337 | |
// value now contains 1337 |
NewerOlder