1、Swift 位移枚举写法
public struct ATRefreshOption :OptionSet {
public let rawValue : Int
public init(rawValue: Int) {
self.rawValue = rawValue
}
public static var none : ATRefreshOption{return ATRefreshOption(rawValue: 0)}
public static var header : ATRefreshOption{return ATRefreshOption(rawValue: 1<<0)};
public static var footer : ATRefreshOption{return ATRefreshOption(rawValue: 1<<1)};
public static var autoHeader : ATRefreshOption{return ATRefreshOption(rawValue: 1<<2)};
public static var autoFooter : ATRefreshOption{return ATRefreshOption(rawValue: 1<<3)};
public static var defaultHidden : ATRefreshOption{return ATRefreshOption(rawValue: 1<<4)};
public static var defaults : ATRefreshOption{return ATRefreshOption(rawValue: header.rawValue|autoHeader.rawValue|footer.rawValue|defaultHidden.rawValue)};
}
2、ObjC位移枚举写法
typedef NS_ENUM(NSUInteger, ATRefreshOption) {
ATRefreshNone = 0,
ATHeaderRefresh = 1 << 0,
ATFooterRefresh = 1 << 1,
ATHeaderAutoRefresh = 1 << 2,
ATFooterAutoRefresh = 1 << 3,
ATFooterDefaultHidden = 1 << 4,
ATRefreshDefault = (ATHeaderRefresh | ATHeaderAutoRefresh | ATFooterRefresh | ATFooterDefaultHidden),
};
相比之下ObjC更加简单明了。
网友评论