Coding Explorer Blog

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

  • Home
  • Apps
  • About
  • Contact

Archives for September 2014

Using a Nested Type in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

In my previous post Classes In Swift — An Introduction, I mentioned that I should probably use an enumeration to denote what the status of my Message was (whether it was sent, received, or read).  Now, I could write a full MessageStatus enumeration with its own file that could be imported into any project, and that would work.  But really, this status is only supposed to talk about my custom class here, about my “Message” class.  Why go through all of the hassle to make this some generic MessageStatus enumeration that could be used on messages completely unrelated to my Message class?

This is exactly where we would want to use a nested type!
[Read more…]

Filed Under: Swift

Classes In Swift — An Introduction

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

Classes are a very important part of any Object Oriented language, and Swift is no exception.  When I explain classes to people, I usually think of one to describe a car.  That’s a bit cliché, and done in a WWDC video, so let’s do something different.

Creating A Class in Swift

Let’s say we are making a chat program in Swift.  It primarily sends messages in text format, but occasionally, it will also send images.  We will first create our more general Message class, which we will specialize into those different formats later:

class Message {
    //Message code goes here
}

[Read more…]

Filed Under: Swift

Swift Dictionary Quick Reference

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

The Swift dictionary is another very useful type of collection in Swift.  Like arrays (which you can read more about in my post Arrays and their Methods in Swift), you access them via subscripts usually.  Unlike Swift arrays though, these subscripts accept many more values besides Ints.  There are some limitations, but it nonetheless gives you a lot more capability than arrays if you need they key used to look it up to be something other than a number.  We will also go over some of the methods for dictionaries as well, but there are not nearly as many as for arrays.
[Read more…]

Filed Under: Swift

Closures and Capturing Values in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

We aren’t done with closures quite yet.  We learned last time about how to write and compress closure expressions in the post Closure Expressions in Swift.  Now, how about we talk about making functions that take them as parameters or return them!  I am still very new to closures, so I do not fully know the power that these hold, so my examples will only show the tip of the iceberg.  When I understand more, I will definitely come back and share, but for the moment, I have to know how to get started with them, so let’s see how that goes.
[Read more…]

Filed Under: Swift

  • « Previous Page
  • 1
  • 2

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