var evens = [Int]()
for i in 1...10 {
if i % 2 == 0 {
evens.append(i)
}
}
var evenSum = 0
for i in evens {
let a: String?
let b: String!
let c: String
a = nil //OK
b = nil //OK
c = nil //NG
navigationController?.toolbarHidden = false
// let hiddenはnil判定かつOptionalの開示された変数なのでwhereがないと条件が真になってしまう
if let hidden = navigationController?.toolbarHidden where isbar {
println(hidden)
}
else {
println(hidden)
}
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 | |
| public func removeObject<T : Equatable>(object: T, inout fromArray array: [T]) | |
| { | |
| var index = find(array, object) | |
| array.removeAtIndex(index!) | |
| } |
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
| http://www.raywenderlich.com/90695/modern-core-graphics-with-swift-part-3 |
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 flatMap<A, B>(x: A?, f: A -> B?) -> B? { | |
| if let x = x { | |
| return f(x) | |
| } 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
| func map<T, U>(xs: [T], f: T -> U) -> [U] { | |
| var result: [U] = [] | |
| for x in xs { | |
| result.append(f(x)) | |
| } | |
| 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
| struct TableSectionRowInfo { | |
| enum RowInfo { | |
| case SecOne1 | |
| case SecOne2 | |
| case SecTwo1 | |
| case SecTwo2 | |
| case SecTwo3 | |
| func rowCount() -> Int { |
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 someOptional:Int? = 42 | |
| if case .Some(let x) = someOptional{ | |
| print("someOptional value is \(x)") | |
| } | |
| if case let x? = someOptional{ | |
| print("someOptional value is \(x)") | |
| } | |
| let arrayOptionalInts:[Int?] = [nil,1,2,3,nil,5] |
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 UIKit | |
| public protocol Groupable { | |
| func sameGroupAs(other: Self) -> Bool | |
| } | |
| extension CollectionType { | |
| public typealias ItemType = Self.Generator.Element | |
| public typealias Grouper = (ItemType, ItemType) -> Bool |