<

Top 5 Swift Features to Maximize your iOS Coding Experience

Published on
4,516 Points
1,116 Views
4 Endorsements
Last Modified:
When Apple released Swift last year, the aim was to introduce a new programming language for Cocoa and Cocoa Touch that was fast, easy and effective, like the name connotes.

Apple succeeded.

Swift is designed to couple with Objective-C programs and be compatible with all current Mac OS X and iOS programs. This means developers can add Swift to existing apps without ripping out older code.

Even better.

Here then, five Swift features guaranteed to maximize your iOS coding experience:


1. Storyboard

Storyboard is the greatest thing about making iOS applications. Any coder who has struggled to create a simple interface with GUI knows with Storyboard in iOS 8 a clean user interface isn’t just attainable, it’s inevitable. Someone with very little to no programming experience can get a nice-looking screen on their app simply by dragging and dropping objects (i.e. buttons, table views, text boxes) to the screen and setting attributes in the sidebar. Options of size, color and allowing the user to interact with the object are also easy changeable via a menu. To traverse the bridge between programming and Storyboard, use a control click and drag from the Storyboard to the class the object will be in. Best of all, the ugliness from the GUI is hidden in Storyboard allowing the programmer to focus on what they’re creating rather than obsessing solely over code.


2. MVC Design

The Model-View-Controller (MVC) design performs exactly as its name suggests. The MVC pattern defines how objects communicate with one another and how they play within the app. More importantly, MVC is a huge time-saver as it promotes reusability and abstraction of your code. Model is the data specific to your app and doesn’t contain anything dealing with the user interface. View is interface the user sees and must be notified by the Controller when data changes. The Controller is the communication link between the Model and View objects. With MVC, you will have cleaner code and find view objects that are both similar and reusable.


3. Optionals

Optionals are Swift’s way of dealing with null values. Any variable type can be optional and is declared by using a ? directly after the variable name. Optionals are key when a variable that may not actually have a value associated with it is used. Say you have a spreadsheet of people’s information and want a print-out, but not every person provided an email or phone number, so the sheet errors out.

With Swift you can say:
if number = numberOptional { println(number) } 

Open in new window

...And boom, print-out successful! Optionals enable programmers to know when a value may not be present and allows applications to run successfully when it isn’t. This may seem tricky at first, but once you get the hang of optionals and know when to use them, they become a failsafe to prevent your app from crashing.


4. Duck-typing

Duck-typing means Swift can infer the variable type so the coder only has to worry that objects perform correctly. It’s important to remember there are exceptions where explicit casting is required. Duck-typing does not work if you want to check a type when you are declaring a class or need to ensure that a variable can only be a certain type. If you haven’t used a language or object environments (Python, Smalltalk) that implements duck-typing it will seem odd at first. Soon enough, you will be thinking less of variables as integers or strings and more as objects.


5. Navigation controllers

Navigation controllers allow for easy movement through screens by providing a navigation bar at the top of each. If the navigation controller is used as the root view controller then every view to follow is pushed onto a stack and added to the navigation bar. The bar will have a back button, a title and is customizable to display what you want and navigate where you want. The navigation controller needs little set-up, its only requirement to be your root view. Do this, and get a simple drop down menu navigation in your app.
4
Comment
0 Comments

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Join & Write a Comment

When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month