Last active
February 6, 2017 12:09
-
-
Save goodmorningcody/ecbdacd83c6eab38366ac7c48c02ebdd to your computer and use it in GitHub Desktop.
complex condition problem - 01
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 Type { | |
case 미국시민권자 | |
case 미국영주권자 | |
case 해당사항없음 | |
case 미국이외조세목적상거주자 | |
case 미국시민권자이면서미국이외 | |
case 미국영주권자이면서미국이외 | |
} | |
struct Tax { | |
var korea: Type? { | |
didSet { | |
if let inKorea = korea { | |
if inKorea == .해당사항없음 { | |
usa = nil | |
abroad = nil | |
} else { | |
korea = nil | |
} | |
} | |
} | |
} | |
var usa: Type? { | |
didSet { | |
if let inUSA = usa { | |
if inUSA == .미국시민권자 || inUSA == .미국영주권자 { | |
korea = nil | |
} else { | |
usa = nil | |
} | |
} | |
} | |
} | |
var abroad: Type? { | |
didSet { | |
if let inAbroad = abroad { | |
if inAbroad == .미국이외조세목적상거주자 { | |
korea = nil | |
} else { | |
abroad = nil | |
} | |
} | |
} | |
} | |
var type: Type? { | |
if let inKorea = korea { | |
if inKorea == .해당사항없음 { | |
return korea | |
} | |
} | |
if let inUSA = usa { | |
if let _ = abroad { | |
if inUSA == .미국시민권자 { | |
return .미국시민권자이면서미국이외 | |
} else if inUSA == .미국영주권자 { | |
return .미국영주권자이면서미국이외 | |
} | |
} else { | |
return usa | |
} | |
} | |
if let _ = abroad { | |
return abroad | |
} | |
return nil | |
} | |
static func create(from type: Type?) -> Tax { | |
guard let unwrappedType = type else { | |
return Tax(korea: nil, usa: nil, abroad: nil) | |
} | |
var tax = Tax(korea: nil, usa: nil, abroad: nil) | |
if unwrappedType == .해당사항없음 { | |
tax.korea = unwrappedType | |
} | |
else if unwrappedType == .미국시민권자 { | |
tax.usa = unwrappedType | |
} | |
else if unwrappedType == .미국영주권자 { | |
tax.usa = unwrappedType | |
} | |
else if unwrappedType == .미국이외조세목적상거주자 { | |
tax.abroad = unwrappedType | |
} | |
else if unwrappedType == .미국시민권자이면서미국이외 { | |
tax.usa = .미국시민권자 | |
tax.abroad = .미국이외조세목적상거주자 | |
} | |
else if unwrappedType == .미국영주권자이면서미국이외 { | |
tax.usa = .미국영주권자 | |
tax.abroad = .미국이외조세목적상거주자 | |
} | |
return tax | |
} | |
} | |
var tax = Tax.create(from: .미국시민권자이면서미국이외) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment