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
| import Foundation | |
| let a = [1,2,3,4,5] | |
| let b = a.flatMap{ (i) -> (Int?) in | |
| if i % 2 == 0 { | |
| return i | |
| } else { | |
| return nil | |
| } | |
| } |
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
| import XCTest | |
| @testable import MyProject | |
| class MyProjectTests: XCTestCase { | |
| var mainvc: MyProject.ViewController! | |
| private func setUpViewControllers() { | |
| let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main) | |
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 appender(delimeter:String)->(String)->String { | |
| var buffer = "" | |
| return { | |
| buffer += $0 + delimeter | |
| return buffer | |
| } | |
| } | |
| let strings = ["a", "b", "c"] | |
| let append = appender(", ") |
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 locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | |
| if let location = locations.first { | |
| print("Found user's location: \(location)") | |
| let session = Session.sharedSession() | |
| var parameters = location.parameters() | |
| let cat = Constants().categoryID() ?? "" | |
| parameters += [Parameter.categoryId:cat] | |
| parameters += [Parameter.intent:"browse"] | |
| parameters += [Parameter.radius:"800"] |
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
| typealias closureType = (Int) -> (Int) | |
| let ff = { return $0 * 2 } | |
| let tt = { return $0 - ff($0) } | |
| func ret(idx: Int, closure: closureType) -> NSNumber { | |
| return NSNumber(integer: closure(idx)) | |
| } |
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 list: [String?] = [nil, nil, "ciao", "hello", nil] | |
| struct Obj { | |
| var group: [String?]? | |
| let name: String? | |
| } | |
| let o1 = Obj(group: list, name: "first") | |
| let o2 = Obj(group: nil, name: "second") |
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 list: [String?] = [nil, nil, "ciao", "hello", nil] | |
| list.reduce([String]()) { | |
| if let e = $1 { | |
| return $0 + [e] | |
| } else { | |
| return $0 | |
| } | |
| } |
NewerOlder