Skip to content

Instantly share code, notes, and snippets.

@philosopherdog
Last active December 8, 2021 17:34
Show Gist options
  • Save philosopherdog/ee7d48e092c0c0b4867758791351c121 to your computer and use it in GitHub Desktop.
Save philosopherdog/ee7d48e092c0c0b4867758791351c121 to your computer and use it in GitHub Desktop.
Swift Unwrap Enum Associated Type Without Switch #enum
enum CommunityProfileSection {
case FacilityName(String?)
case ContactInfo(ProfileContactViewModel)
case LocationInfo([ExpandableProfileModel])
}
extension CommunityProfileSection {
var facilityName: String? {
if case let .FacilityName(name) = self {
return name
}
return nil
}
var locationInfoList: [ExpandableProfileModel] {
if case let .LocationInfo(list) = self {
return list
}
return []
}
var contactInfo: ProfileContactViewModel? {
if case let .ContactInfo(info) = self {
return info
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment