Displacement enumeration details, displacement Enumeration

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.