Displacement enumeration details, displacement Enumeration
Enumeration:
In mathematics and computer science theory, the enumeration of a set is a program that lists all the members of a certain set of finite sequences, or the counting of a specific type of object. These two types often (but not always) overlap. [1] is a set of named Integer constants, which are common in daily life, for example, an enumeration is used to indicate SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY of a week.
In iOS, we see the most common enumeration and displacement enumeration.
Normal Enumeration
In the OC environment of Xcode, you can use NS_ENUM to quickly extract the enumeration. In Swift, press enum and press Enter.
Objective-C
Typedef NS_ENUM (NSUInteger, DirectionType) {diretypetypeup, diretytypeleft, DirectionTypeDown, diretytyperight,}; // The method of use is xxx. type = DirectionTypeUp;
Swift
Enum localtype: NSInteger {case left case middle} // orenum type {case left case middle} // xxxx. type =. left
Displacement enumeration Objective-C displacement Enumeration
In OC, we useNsoptions to quickly extract the displacement Enumeration
Typedef NS_OPTIONS (NSUInteger, MyEnum) {MyEnumValueA = 1 <0, // decimal 1 MyEnumValueB = 1 <1, // decimal 2 MyEnumValueC = 1 <2, /// decimal 4 };
Swift displacement Enumeration
public struct UIViewAutoresizing : OptionSet { public init(rawValue: UInt) public static var flexibleLeftMargin: UIViewAutoresizing { get } public static var flexibleWidth: UIViewAutoresizing { get } public static var flexibleRightMargin: UIViewAutoresizing { get } public static var flexibleTopMargin: UIViewAutoresizing { get } public static var flexibleHeight: UIViewAutoresizing { get } public static var flexibleBottomMargin: UIViewAutoresizing { get }}
Use of enumeration
Use of general enumeration in Objective-C
Xxx. type = xxxtype; // enter the full name.
Use of common enumeration in Swift
Xxx. type =. xxx; // The enumeration in Swift is basically to write a type, and then each "case" in it is relatively simple. for example ". left ",". right.
In general, the use of general enumeration in Objective-C and Swift is not much different.
Use of displacement enumeration in Objective-C
Xxx. type = xxxtype1 | xxxtype2; // use "|" to indicate multiple enumerations
Use of the shift enumeration in Swift
Xxx. type = [. type1 ,. type2 ,. type3] // Note: Do not use "|" when using the shift enumeration in swift, because the definition of the Swift shift enumeration is more similar to a "class ". the usage is not the same.