Last active
September 3, 2015 07:03
-
-
Save Kametrixom/437a607e16eacf08e9c1 to your computer and use it in GitHub Desktop.
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
// Make this code compile without changing these lines | |
func raw<T: RawRepresentable>(t: T) -> T.RawValue { | |
return t.rawValue | |
} | |
let array : [E] = [.A(true), .B(1), .C("C")] | |
array.map(raw) | |
if case .C(let s?)? = array.first {} | |
// If you want a bigger challenge, include this part: | |
for elem in array { | |
switch elem { | |
case .C(_): | |
print("C!") | |
} | |
} |
enum E : RawRepresentable {
case C(String?)
init?(rawValue: String) {
self = .C(rawValue)
}
static func A(x: Bool) -> E {
return .C(String(x))
}
static func B(x: Int) -> E {
return .C(String(x))
}
var rawValue: String {
switch self {
case let .C(value): return value ?? ""
}
}
}
Congrats to @kostiakoval for solving the challenge when there wasn't an extended version yet
Congrats to @pyrtsa for solving the extended challenge ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No full challenge :)