Last active
February 23, 2017 17:43
-
-
Save d-date/393232109fb301269770f3490d47fbe5 to your computer and use it in GitHub Desktop.
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
//見た目は同じ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