Last active
February 3, 2018 23:20
-
-
Save erica/2d9ef84b5ebda7454ca4 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
Dump: | |
▿ Features | |
- rawValue: 34 | |
Disposition: Struct [Features] | |
ValueType: Features | |
Value: Features(rawValue: 34) | |
Summary: Features | |
Subreferences: 1 children | |
Element Name: rawValue | |
Dump: | |
- 34 | |
QuickLook: [Int] 34 | |
Disposition: Aggregate [Swift.Int] | |
ValueType: Swift.Int | |
Value: 34 | |
Summary: 34 |
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
Dump: | |
▿ CustomMirror.Features | |
- rawValue: 34 | |
QuickLook: [Text] [Alarm System, Leather Interior] | |
Disposition: Aggregate [CustomMirror.Features] | |
ValueType: CustomMirror.Features | |
Value: [Alarm System, Leather Interior] | |
Summary: [Alarm System, Leather Interior] | |
Subreferences: 2 children | |
Element Name: Alarm System | |
Dump: | |
▿ CustomMirror.Features | |
- rawValue: 2 | |
Disposition: Struct [CustomMirror.Features] | |
ValueType: CustomMirror.Features | |
Value: [Alarm System] | |
Summary: CustomMirror.Features | |
Subreferences: 1 children | |
Element Name: rawValue | |
Dump: | |
- 2 | |
QuickLook: [Int] 2 | |
Disposition: Aggregate [Swift.Int] | |
ValueType: Swift.Int | |
Value: 2 | |
Summary: 2 | |
Element Name: Leather Interior | |
Dump: | |
▿ CustomMirror.Features | |
- rawValue: 32 | |
Disposition: Struct [CustomMirror.Features] | |
ValueType: CustomMirror.Features | |
Value: [Leather Interior] | |
Summary: CustomMirror.Features | |
Subreferences: 1 children | |
Element Name: rawValue | |
Dump: | |
- 32 | |
QuickLook: [Int] 32 | |
Disposition: Aggregate [Swift.Int] | |
ValueType: Swift.Int | |
Value: 32 | |
Summary: 32 |
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
public struct Features : OptionSetType { | |
public let rawValue : Int | |
public init(rawValue: Int) {self.rawValue = rawValue} // workaround, :(, silly Apple | |
public static let AlarmSystem = Features(rawValue: 1 << 1) | |
public static let CDStereo = Features(rawValue: 1 << 2) | |
public static let ChromeWheels = Features(rawValue: 1 << 3) | |
public static let PinStripes = Features(rawValue: 1 << 4) | |
public static let LeatherInterior = Features(rawValue: 1 << 5) | |
public static let Undercoating = Features(rawValue: 1 << 6) | |
public static let WindowTint = Features(rawValue: 1 << 7) | |
public static func members() -> [Features] { | |
var i = 1 | |
return Array(anyGenerator{return i <= 7 ? Features(rawValue: 1 << i++) : nil}) | |
} | |
public var flagset: [Features] { | |
var flags = [Features]() | |
for flag in 1...7 where contains(Features(rawValue:1<<(flag))) { | |
flags.append(Features(rawValue:1<<(flag))) | |
} | |
return flags | |
} | |
public var rawflagset: [Int] { | |
var flags = [Int]() | |
for flag in 1...7 where contains(Features(rawValue:1<<(flag))) { | |
flags.append(1<<(flag)) | |
} | |
return flags | |
} | |
public var names : [String] { | |
var nameArray = [String]() | |
let strings = ["Alarm System", "CD Stereo", | |
"Chrome Wheels", "Pin Stripes", "Leather Interior", | |
"Undercoating", "Window Tint"] | |
for (flagLessOne, string) in strings.enumerate() where contains(Features(rawValue:1<<(flagLessOne + 1))) { | |
nameArray.append(string) | |
} | |
return nameArray | |
} | |
} | |
extension Features : CustomPlaygroundQuickLookable { | |
public func customPlaygroundQuickLook() -> PlaygroundQuickLook { | |
return QuickLookObject.Text(names.description) | |
} | |
} | |
extension Features : CustomDebugStringConvertible { | |
public var debugDescription : String { | |
return names.description | |
} | |
} | |
extension Features : CustomReflectable, MirrorType { | |
/// The instance being reflected. | |
public var value: Any {return self} | |
/// Identical to `value.dynamicType`. | |
public var valueType: Any.Type {return self.dynamicType} | |
/// A unique identifier for `value` if it is a class instance; `nil` | |
/// otherwise. | |
public var objectIdentifier: ObjectIdentifier? {return nil} | |
/// The count of `value`'s logical children. | |
public var count: Int { | |
let fs = self.flagset | |
return fs.count == 1 ? 0 : fs.count | |
} | |
public subscript (i: Int) -> (String, MirrorType) { | |
return (names[i], reflect(flagset[i])) | |
} | |
/// A string description of `value`. | |
public var summary: String { | |
return names.description} | |
/// A rich representation of `value` for an IDE, or `nil` if none is supplied. | |
public var quickLookObject: QuickLookObject? { | |
return QuickLookObject.Text(names.description)} | |
/// How `value` should be presented in an IDE. | |
public var disposition: MirrorDisposition {return .Aggregate} | |
public func customMirror() -> Mirror { | |
return Mirror(reflecting: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment