Mutable Function Parameters

Today I decided to take a look at the upcoming Swift 3.0 changes. If you are interested in reading about implemented proposals, please see Swift Evolution page on Github. This article is in addition to the article I wrote about Swift 2.2 changes that can be found here.

SE-0003: Removing var from Function Parameters – is the one I want to talk about. Function parameters, by default, are constants. However, it was possible to declare the parameter as a variable.

Continue reading “Mutable Function Parameters”

Mutable Function Parameters

Two Reasons We Needed Swift

Swift needed to happen. Objective-C had no future. I know this is a harsh statement, but this is the conclusion I came to this week after writing purely in Swift for a few months now. It is hard to admit, especially after spending most of my software development career writing in Objective-C. There is a chance that a lot of you will disagree with this statement, but let me mention two things I find lacking in Objective-C that are extremely important when it comes to writing good code.

Objective-C by its nature is a much forgiving language (and I am using this term loosely). It allows developers to get away with bad code. It does not impose requirements for handling errors. It allows for nil return type where a specific type is expected. It does not guarantee immutability. It requires extra work to declare true constants. Block syntax (should I say more)?.

Continue reading “Two Reasons We Needed Swift”

Two Reasons We Needed Swift

Core Data – Renaming Attributes

Weekends are awesome. I don’t get up super early and most of the time get an opportunity to work on personal projects, read up on new advances in Swift, catch up on news, etc.

Today I needed to migrate my Core Data model to a new version. Fortunately for me, light weight migration was enough and I didn’t have to perform the migration using a Mapping Model. Renaming attributes however is a bit more involved than simply adding attributes. This, of course, meant I would have something to write about… although, admittedly, I had another topic in mind for this week’s article.

Light weight migrations are pretty straight forward; Core Data takes care of everything by inferring mapping model from differences between the source and destination models.

Continue reading “Core Data – Renaming Attributes”

Core Data – Renaming Attributes

Retain Cycles in Swift

Retain cycles is a very interesting topic.

What picked my brain about retain cycles in Swift though is the actual absence of the warning you get when capturing self strongly inside of a block unlike when writing purely in Objective-C. Let me demonstrate what I am talking about. Let’s assume we are building a simple calculator app that only supports 4 mathematical operations: add, subtract, multiply, and divide. Let’s also assume that in place of a regular method, we will write a block that will perform the calculation for specified operation and set the text of the UILabel to the resulting value.

First of all, let’s declare an enum to keep track of all supported operations:

Continue reading “Retain Cycles in Swift”

Retain Cycles in Swift

It’s The Little Things That Matter…

Since I started at Code Fellows as a Sr. iOS Engineer / Instructor a few month ago, I decided I am going to write an article a week on topics I find interesting when it comes to Swift, Objective-C, or iOS in general.

This week I would like to simply take the time to appreciate the awesomeness of Swift – but not just any version of Swift, I would like to talk specifically about Swift 2.0.

Granted, it’s the second major release of the language (although some can argue, and rightfully so, that Swift 1.2 was somewhat a major release), it’s already on par with Objective-C which, as of writing this article, is stable at version 2.0… Let me get off track for a second please. Every time I mention Objective-C, I feel a bit nostalgic. I started developing in Objective-C years ago… days before ARC and all of the out-of-the-box features we, iOS developers, enjoy today (thank you Apple). Objective-C will always be part of my developers vocabulary.

Anyway, Swift 2.0…

Continue reading “It’s The Little Things That Matter…”

It’s The Little Things That Matter…

Swift At Work…

I’ve been going through my projects for the past few weeks updating them to Swift 2.0. In particular, I released MBGithubOAuthClient a few years back that I needed to rewrite in Swift. To show how awesome and safe Swift is, here are two functions side-by-side:

This is the same function is Swift:

As you can see, there is no reason to type check and write throwException function anymore. Awesome.

Swift At Work…

mcPKG Project

mcPKG is the project I worked on last year. It is written in Objective-C.

The purpose of this app was to communicate with JotForm API to retrieve user submission / files and then generate a control file that later on would be used to create UNIX executables. It uses Core Data to keep local database in sync with servers.

In addition to using JotForm APIs, this app also utilizes Parse API to separately store user data (user registration processed from JotForm). It uses Facebook SDK, AFNetworking, MagicalRecord, etc.

This project also demonstrates a good understanding on REGEX for input validation. It can also be used as an example of how to process HTML files into foundation objects.

All-in-all, this project took me a couple of month to draft and complete. It was insanely fun to implement. It is 100% functional given the right API keys and URLs.

Continue reading “mcPKG Project”

mcPKG Project