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
func someFunction<T>(_ argument1: T, _ argument2: T) {} | |
someFunction(1, 2) // OK | |
someFunction("abc", "def") // OK | |
// someFunction(1, "abc") // 型引数が一致しないためコンパイルエラー |
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
class Person { | |
let name : String | |
init(name: String) { | |
self.name = name | |
} | |
} | |
class User : Person { | |
let id : Int | |
init(id : Int) { |
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
class SuperClass { | |
var value = 1 | |
} | |
class SubClass: SuperClass { | |
fileprivate var _subValue: Int! = nil {//サンプルとしてfileprivateでしているけど本当はprivateのほうがいいかも | |
willSet { | |
guard newValue != nil else { | |
fatalError("nilだよ") | |
} |
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
class SomeClass { | |
let id: Int | |
init(id: Int) { | |
self.id = id | |
} | |
deinit { | |
print("remove") | |
} | |
} |
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
enum SomeError: Error { | |
case error1 | |
case error2(reason: String) | |
} | |
do { | |
throw SomeError.error2(reason: "何かがおかしいようです") | |
} catch SomeError.error1 { | |
print("error1") | |
} catch SomeError.error2(let reason) { |
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
Result<User, ~~Error> | |
let r1 = findUser(byID: 123) | |
let r2 = r1.flatMap{ localRart (fromEmail: $0.email) | |
//r2はResult<String, ~~Error)になる |
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
class Rational (val numerator: Int, val denominator : Int){ | |
override fun toString(): String = "${numerator}/${denominator}" | |
} |
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
/** | |
* Created by satoutakeshi on 2017/07/17. | |
*/ | |
fun main(args : Array<String>) { | |
val result = succ(31) | |
println(result) | |
println(square(5)) | |
println(hello("sato")) | |
println(max(2, 4)) | |
println(sum(arrayOf(1,2,3))) |
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 config = try Config() | |
try config.setup() | |
let drop = try Droplet(config) | |
drop.get("qiitaSchema") { req in | |
guard let resultJson = try drop.client.get("http://qiita.com/api/v2/schema").json else { | |
throw Abort.serverError | |
} | |
return resultJson |
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
fun foo() { | |
ints.forEach { | |
if (it == 0) return@forEach | |
print(it) | |
} | |
} |