Coding Explorer Blog

Exploring how to code for iOS in Swift and Objective-C

  • Home
  • Apps
  • About
  • Contact

Pattern Matching in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

Pattern matching is a staple of functional languages.  At its core, Swift is primarily an object-oriented language, like Objective-C is.  However, there are many advantages to the way more functional style languages like Haskell and Erlang do things that the designers of Swift decided to include.  Pattern matching in particular, saves us having to type much longer, and less readable statements to do the same checks.

I mean, which is easier to read:

case (_, 0, 0):

or

if (someTuple.1 == 0) && (someTuple.2 == 0)

They both will find the same thing, but one can be used in a switch statement, and the other has to dig into the internals of a tuple and write a much longer looking comparison to 0 for each.  Not to mention the logical && there, to make sure both of them are true.
[Read more…]

Filed Under: Swift Tagged With: Swift

Choosing Images with UIImagePickerController in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

If your Swift iOS app needs to import a picture from the user’s device, you’ve come to the right place today.

Let’s learn how to use UIImagePickerController to let the user select a photo from their device to load into your app.
[Read more…]

Filed Under: Tutorial Tagged With: Swift

Integers and Numeric Literals in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

Numbers are the building blocks of any piece of software.  It eventually gets all the way down to our code being translated into a series of numbers that refer to specific CPU instructions and data to use with them.  We will stay well above that level in this post, but I thought it would be useful to share some of the special aspects of how numbers, particularly Integers, are handled in Swift.
[Read more…]

Filed Under: Swift Tagged With: Swift

Swift Set Type

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

In Objective-C there were three basic types of Data Structures, NSArray, NSDictionary, and NSSet.  In Objective-C, the immutable and mutable forms were separate, so you also had NSMutableArray, NSMutableDictionary, and NSMutableSet.  Especially since it is often an interview question, I should point out that a Data Structure is simply “a particular way of organizing data in a computer so that it can be used efficiently.”  You can read that sentence and more at the Wikipedia article about Data Structures.

In Swift we were greeted with Arrays and Dictionaries, but there was no Set to be found!  You had to go back to Objective-C’s NSSet to work with them.  You can read about the other two Data Structures back in the previous posts Arrays and their Methods in Swift and Swift Dictionary Quick Reference.  Well, thanks to Swift 1.2, Set has come to the land of Swift.
[Read more…]

Filed Under: Swift Tagged With: Swift

Multiple Optional Bindings in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

Shortly after my last post Segue from UITableViewCell Taps in Swift, Apple released Xcode 6.3 Beta 1, which includes Swift 1.2.  There are many updates to the language that I was quite happy about, but let’s talk about my favorite one today, improved Optional Binding.

The new version allows you to bind multiple optionals, as well as check a boolean expression related to them in a single line, avoiding the nesting we currently must do when working with multiple Optional Bindings.
[Read more…]

Filed Under: Swift Tagged With: optionals, Swift

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • Next Page »

Subscribe to the Coding Explorer Newsletter

* indicates required

Follow Us

Facebooktwitterrss

Recent Posts

  • Error Handling in Swift
  • Creating and Modifying a URL in your Swift App
  • Watch Connectivity in Swift — Application Context
  • watchOS Hello World App in Swift
  • API Availability Checking in Swift

Categories

  • Class Reference
  • General
  • Interface Builder
  • My Apps
  • Objective-C
  • Swift
  • Syntax
  • Tutorial
  • Uncategorized

Archives

  • May 2016
  • March 2016
  • February 2016
  • December 2015
  • July 2015
  • June 2015
  • April 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • January 2014
  • November 2013
  • September 2013
  • August 2013
  • July 2013
  • Terms Of Use
  • Privacy Policy
  • Affiliate Disclaimer

Subscribe to the Coding Explorer Newsletter

* indicates required

Copyright © 2025 Wayne Media LLC · Powered by Genesis Framework · WordPress