Masking your bits — Swift OptionSet Tutorial

Image for post
Image for post

What is bitmask?

Image for post
Image for post
Image for post
Image for post

Objective C Way

  00000001 // Deleted
| 00000010 // Archived
--------------------
= 00000011 // Deleted | Archived

OptionSet Protocol — Swift Solution

view.autoresizingMask = .flexiableHeight
view.autoresizingMask = [.flexibleHeight ,.flexibleWidth]
view.autoresizingMask = []
if toppings.contains(.bacon) {
// do something
}

Int / Int8 / Int16 / Int32 -> FixedWidthInteger

Summary

Head of Mobile Any.do, Author of “Pro iOS Testing”

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store