This file contains hidden or 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
| descriptionAttributedString.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.blue, range: NSRange(location: 0, length: 2)) |
This file contains hidden or 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
| attributedString.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.black.withAlphaComponent(0.5), range: NSRange(location: 5, length: 4)) |
This file contains hidden or 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 array = [1, 2, 3, 4, 5] | |
| let arrayReturned = array.map({ (number: Int) -> Int in | |
| let result = 2 * number | |
| return result | |
| }).map({ (number: Int) -> Int in | |
| let result = number / 2 | |
| return result | |
| }) |
This file contains hidden or 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 set:Set = [1, 2, 3, 4, 5] | |
| let setReturned = set.map({ (number: Int) -> Int in | |
| let result = 2 * number | |
| return result | |
| }) |
This file contains hidden or 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 optional:Optional = 1 | |
| let optionalReturned = optional.map({ (number: Int) -> Int in | |
| let result = 2 * number | |
| return result | |
| }).map({ (number: Int) -> Int in | |
| let result = number / 2 | |
| return result | |
| }) |
This file contains hidden or 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 dictionary:Dictionary = [1:"int",3:"hi"] | |
| let dictionaryReturned = dictionary.map({ (key: Int, value: String) -> Int in | |
| let result = 2 * key | |
| return result | |
| }) |
This file contains hidden or 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
| protocol Multipleiable { | |
| static func * (lhs: Self, rhs: Self) -> Self | |
| } | |
| extension Int: Multipleiable {} | |
| extension Double: Multipleiable {} | |
| infix operator ** : MultiplicationPrecedence | |
| func **<T> (lhs: T, rhs: T) -> T where T: Multipleiable { |
This file contains hidden or 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
| infix operator ** : MultiplicationPrecedence | |
| func ** (lhs: Int, rhs: Int) -> Int { | |
| return lhs * rhs | |
| } | |
| 3 ** 4 | |
| // result : 12 |
This file contains hidden or 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 **<T> (lhs: T, rhs: T) -> T where T: Multipleiable { | |
| return lhs * rhs | |
| } |