Coding Explorer Blog

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

  • Home
  • Apps
  • About
  • Contact

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

Custom Operators in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

You have been spared the terrible pun for this title, I knew the last one was trouble when it was typed in.

So, in the earlier article Operator Overloading — Tailor Swift To Your Needs, you saw how you could add functionality to already existing operators to extend their functionality to work with new classes, or in that post’s case, existing ones that it might make sense with.  Now, what if you want a completely new operator?  What if you have functionality so unique, that no current operator makes sense?  That’s where custom operators comes in.  You can declare your own operator and have it run whatever code you want.  Now, like last time, this is a very powerful, but very dangerous capability.  You COULD have it play sounds, make network calls, draw something to screen, or any number of annoying things, but you really should not have those in your operator overloading or custom operator methods.  They are meant to make things more readable, not less.  Unless you use some emoji for a loudspeaker in your operators, you really shouldn’t have it play sounds, and even if you do, why not just use a method?

Also of course, since these are meant to increase readability, you have to be careful about using these.  For instance, can you tell me what the ” #$^&* ” operator does?  Obviously somebody new to a codebase needs some time to get up to speed with it, and even normal functions will take some time to learn the intricacies of.  However, if you compress a gigantic algorithm into a custom operator, that may take longer to figure out than a well named method doing the same.

Nonetheless though, if you use custom operators sparingly, well document them, and don’t give them side effects (like making network calls, playing sounds, etc), they can very useful for increasing legibility and decreasing the character count in your code.
[Read more…]

Filed Under: Swift

Execution States for a Swift iOS App

Last updated on January 10, 2015

Time to start moving away from pure Swift posts, and start talking about making iOS apps.  Though we will be talking about doing so with Swift, of course.  Today we are going to talk about the Five Execution states of an iOS app.  The iOS operating system itself changes which state your app is in, and gives you a chance to make appropriate changes during most of the transitions.
[Read more…]

Filed Under: Swift

Generic Types in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

We have previously discussed generic functions on this blog in the post Generic Functions in Swift.  There is one more aspect to generics in Swift that we have not covered yet, Generic types.  Generic types let you write a named type (class, enumeration, or structure) that can accommodate different types in its implementation.

Now, that just sounds silly right there, why would you want to handle other types in your type?  Well, the main and most predominant reason is for collections.  The best example of this, is the built in Array and Dictionary types.  The shorthand is a lot more readable, and is the recommended way to create Arrays and Dictionaries, but really, [Int] and [String : Int] are actually Array<Int> and Dictionary<String, Int> under the hood.  See those angle brackets?  Yep, those are the same kind of angle brackets used in generic functions.
[Read more…]

Filed Under: Swift

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • …
  • 9
  • 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