Created
November 17, 2015 10:24
-
-
Save yarshure/8f4b3c695534aa2c8395 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
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