Skip to content

Instantly share code, notes, and snippets.

@haranicle
haranicle / CodePiece.swift
Created July 31, 2015 16:45
??? #CodePiece
Realm().write {
Realm().deleteAll()
}
let turtle = Animal()
turtle.name = "Turtle"
turtle.legCount = 4
Realm().write {
Realm().add(turtle)
@haranicle
haranicle / CodePiece.swift
Created July 25, 2015 06:33
PatternMatchingについて #cswift #CodePiece
if case let .OSX(version) = platform {
print(version)
}
if case let value? = optionalValue {
}
if case let (a?, b?, c?) = (optionalA, optionalB, optionalC) {
// optionalA,B,Cすべてがoptionalじゃないときだけ実行される
print(\(a)\(b)\(c))
@haranicle
haranicle / CodePiece.swift
Created July 25, 2015 06:13
do-catchについて #cswift #CodePiece
// エラーハンドリング専用構文
do {
// エラーが発生する可能性があるコード
} catch {
// エラー発生時の処理
}
// 例
do {
@haranicle
haranicle / CodePiece.swift
Created July 25, 2015 06:00
repeat-whileについて #cswift #CodePiece
repeat {
// ここを実行後にexpressionを評価
} while expression
// 例
var count = 100
repeat {
--count
} while count > 0
@haranicle
haranicle / CodePiece.swift
Created July 25, 2015 05:40
deferについて #cswift #CodePiece
var handle:Handle = File.open(path)
// defer はスコープを抜ける直前に"必ず"実行される
defer {
print("close")
handle.close()
}
// 複数deferすることもできる
defer {
@haranicle
haranicle / CodePiece.swift
Last active August 29, 2015 14:25
guardについて #cswift #CodePiece
guard let value != 0 else {
// ここでスコープを抜ける処理
return
break
continue
fatalError()
}
// 上の条件が満たされていることを前提としたコードが書ける
print( 100 / value )
@haranicle
haranicle / CodePiece.swift
Created July 25, 2015 05:09
てすと #cswift #CodePiece
print("hello world")
@haranicle
haranicle / gist:4171703b6d0d2536fdb8
Created July 16, 2015 05:45
'RLMException', reason: 'Index is out of bounds.'
2015-07-16 14:44:42.806 AlcatrazTour[71604:2586803] *** Terminating app due to uncaught exception 'RLMException', reason: 'Index is out of bounds.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e81bc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000110386bb7 objc_exception_throw + 45
2 Realm 0x000000010df7c5e7 -[RLMResults objectAtIndex:] + 343
3 Realm 0x000000010df7e5ae -[RLMResults objectAtIndexedSubscript:] + 62
4 AlcatrazTour 0x000000010dbc6c2c _TFC12AlcatrazTour25PluginTableViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 140
5 AlcatrazTour 0x000000010dbc6f1f _TToFC12AlcatrazTour25PluginTableViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
6 UIKit 0x000000010f1bb9e8 -[U
PS1='\W🍣 \$'
@haranicle
haranicle / Install bundler alias
Last active August 29, 2015 14:23
Install bundler alias
alias gemgen='rbenv local 2.1.2 && bundle init'
alias geminstall='bundle install --path=vendor/bundle --binstubs=vendor/bin'