Category: Swift

Getting Started with CocoaPods

Installation make sure the ruby system is up to date $ sudo gem update –system install cocoapods $ sudo gem install cocoapods If you get an error message about fuzzy_match, try this command instead, $ sudo gem install -n /usr/local/bin cocoapods setup the pods $ pod setup To Test / use cocoa pods Create a […]

Detecting iPad or iPhone in swift

To detect if the user is using an iPad or iPhone or something else in Swift do something like this: switch UIDevice.current.userInterfaceIdiom { case .phone: deviceLavel.text = “iPhone” case .pad: deviceLavel.text = “iPad” case .unspecified: deviceLavel.text = “unspecified” case .tv: deviceLavel.text = “tv” case .carPlay: deviceLavel.text = “carPlay” }

Optionals in Swift 3

Swift Optionals A type the either has a “wrapped” value or is nil. e.g. let imagePaths = [“star”: “/glyphs/star.png”,”portrait”: “/images/content/portrait.jpg”,”spacer”: “/images/shared/spacer.gif”] Getting a dictionary’s value using a key returns an optional value, so imagePaths[“star”] has the type String? e.g. if let imagePath = imagePaths[“star”] { print(“The star image is at ‘(imagePath)'”) } else { print(“Couldn’t […]