Monthly Archives:September 2017

The Swift Programming Language tutorial completed…however

So I completed The Swift Programming Language Tutorial from Apple Developer Site today. It took me for about a month. I understand probably 60% of the concept. Off course I know terminologies of  protocols, extensions, closures,  generics, and so on, but do I know when to use and how? Hell no… So my learning continues.

I found myself lack of understanding of Object Oriented Programming concept. I wasn’t learning it in a way what it means in coding. So this is my first assignment in October.

Meantime, Swift 4 is out. I was reading first 100 pages or so of Swift 4 version of this tutorial, and found quite a few changes from Swift 3. So learning those changes in Swift 4 will be another assignment, but before I do it, I need to assess additional cost to buy a new MacBook Pro to run Xcode 9 on and iPhone 8 or X, and perhaps Apple Watch. My current MacBook Pro is from 2012, too ancient to run the latest tools. Even Xcode 8 runs like an old man running to a donut shop at 6 am in the morning. I’m talking about myself.

Anyway, learning OOP and watching videos and reading technical blogs about Swift/iOS development will continue, and most importantly, I want to try making simple apps using GitHub. This should be second objective in October. Switching to Swift 4 would be December or early next year.


Brian Moriguchi


(Excerpt from Swift Programming 101: The Power of Extensions)

Extensions allow you to add behavior to existing classes, including classes in the Cocoa Touch Framework. Apple can’t add every feature you want to their framework classes, but they have provided a tool to allow you to do it yourself.

Swift’s extensions allow you to extend classes, structures and enumerations without creating a subclass. It’s better to create an extension to add functionality to a Cocoa Touch Framework class than to create a subclass, because it allows you to use the standard Cocoa Touch class throughout your app. For example, if you add an extension to the NSURLclass, you can still use NSURL throughout your app. You don’t have to remember to use a custom subclass in some places and NSURL in others.

Brian Moriguchi

Classes and Structures Explained from Sean Allen’s YouTube

Classes are reference-type, and Structures are value-type. Think of a reference type as a Google Drive spread sheet file which everybody can access and edit, whereas a value-type as a Microsoft Excel file attached to your email. When somebody edits a file on Google Drive, there is no original any more, however you always have the original on your PC even after somebody edited the email attachment file.

Classes must have initializers, but Structures don’t have to.

Classes can have inheritance, but Structures doesn’t.

Summarized from Sean Allen’s You Tube video.

Brian Moriguchi

Parameters and Arguments

Excerpt from an article “Swift 3: What’s Changed?” on

A parameter is like a parking spot, and the argument is the car you park in it. It’s OK if you call everything a parameter – it’s all input for a function, anyway.


Brian Moriguchi

Functions, Objects, Classes, Attributes, Methods


An application is, generally, actually a collection of several smaller applications, called functions. Functions are mini-programs that live within your application to perform very specific tasks. For example, in your email client, a function exists that connects to your mail server and asks if there are any new messages. If there are, it will pass the work on to a different function that downloads the mail to your computer. Yet another function exists that displays the new messages in your mail client, so you can read them.

Excerpt from LEARNING SWIFT web site “The Basic”



Objects are best thought of as somewhat generic, empty containers of code that can be reused throughout your site. Objects are defined by blocks of code called Classes.


Classes provide a clean and simple way to work with data within your application in a way that can be easily extended, modified, and maintained. Though you define a Class once, you can create as many Objects in your code as you wish, each one acting as an independent entity within your application.

For example, if you were creating a blogging application, you might create individual Classes for blog entries, categories, comments, and users. Each of these classes would have unique attributes and methods that were relevant for the type of data they contained.

Attributes and Methods

Objects have descriptive attributes and often contain methods.

Attributes are another name for variables that are specific to the object you are creating.  They are localized containers for information about the specific object you have created.

Using the example above (a blogger application), let’s say we wanted to create an object for users.  We would want to create an object called User, and define the following attributes:

  • Name
  • Username
  • Email address
  • Password
  • Internal user id
  • Twitter handle
  • Website URL

Methods are functions, or procedures, that are specific to the object being created.  For example, you might want functions for your users that:

  • Add a new user
  • Delete a user
  • Search for a user

You could create a number of functions in your code to deal with user data, and come up with function names like AddUserToDatabase, DeleteUserFromDatabase, etc. Or, you can create a User object, and attach add(), delete(), and search() functions to it.


class User {
  var name = String()
  var username = String()
  var emailaddress = String()
  var password = String()
  var userid = Int()
  var twittername = String()
  var siteurl = String()
  func add() -> Boolean() {
    // code to add user record to your data store
  func delete() -> Boolean() {
    // code to delete user record from your data store

When you want to make use of the object in Swift, it will look like the following:

var user = User(); = "Darren" = ""
user.password = "password"
println( // Prints Darren
user.add() // Adds the user Darren to the data store

OK, so what’s the benefit?

There’s a number of benefits to using objects in your code:

  • Less coding for repetitive operations, and cleaner code that’s easier to read and understand
  • Easier maintenance
  • Abstraction
  • Backwards compatibility


Excerpt from LEARNING SWIFT web site “Object Oriented Programming Primer


Brian Moriguchi