Skip to content

Instantly share code, notes, and snippets.

@yarshure
Created November 17, 2015 10:24
Show Gist options
  • Save yarshure/8f4b3c695534aa2c8395 to your computer and use it in GitHub Desktop.
Save yarshure/8f4b3c695534aa2c8395 to your computer and use it in GitHub Desktop.
enum Either<T1, T2> {
case Left(T1)
case Right(T2)
}
public class MyClas {
func mytest<T:CustomStringConvertible>(a:T) ->String{
return "\(a)"
}
func test(list:[String]) ->String{
return "abcd"
}
func test(list:[String:String]) ->String{
return "abcdf"
}
func process(json:[String:String]) -> Either<String,[String]>{
guard let name = json["name"] else{
return .Right(["array"])
}
return .Left(name)
}
}
let my = MyClas()
print(my.mytest(["this is array"]))
print(my.mytest(["key":"value"]))
let name = my.process(["name" : "yarshure"])
switch name{
case .Left(let text):
print(text)
case .Right(let list):
print(list)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment