Skip to content

Instantly share code, notes, and snippets.

@d-date
Last active February 23, 2017 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-date/393232109fb301269770f3490d47fbe5 to your computer and use it in GitHub Desktop.
Save d-date/393232109fb301269770f3490d47fbe5 to your computer and use it in GitHub Desktop.
//見た目は同じInitializer。単数か複数かは気にする必要なし。勝手にsingleかmultipleに振り分けてくれる。
enum PossibleArrayType<T> {
case single(T)
case multiple([T])
init(_ single: T) {
self = .single(single)
}
init(_ multiple([T]) {
self = .multiple(multiple)
}
}
func create() {
switch type {
case .hoge:
let str: String = try e <| "data"
return PossibleArray(str) //ひとつ
case .fuga:
let array: [Custom] = try e <|| "data"
return PossibleArray(array) //複数
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment