Thinking in Swift (Part I) - Introduction

December 01, 2014 in Mobile Development Articles

Written by Jason Bell


When it comes to developing software in the Apple Universe (OS X and iOS), Objective-C is now the “old and busted” while Swift is the “new hotness”.

SwiftThere are already dozens of resources on the Web for learning how to create “Hello World” in Swift, declare a variable, write a function, and so on. Apple has made available three wonderful documents that cover the essentials:

There is also no shortage of people trying to distill the hotness into a Twitter-like 140 characters or less.

  • Industrial-quality systems programming language that is as expressive and enjoyable as a scripting language.
  • A modern, safe, fast, interactive, and interoperable language used to write code for Apple’s platforms.
  • Objective-C without the C.
  • Freedom from square brackets.
  • The ability to combine two strings by using the + operator (I always felt bad explaining the absence of that one to new Objective-C programmers).

Personally, I’m a long-time Objective-C programmer who still actually enjoys using the language. Of course, I also very much enjoy writing C++ so maybe I need some professional help.

Anyway, my goal with this series of articles is not to give you a basic tutorial on how to write Swift. As I said, there are more than enough places to go for that. What I will do is give you some insight into what Chris Lattner and his compatriots at Apple were thinking when they came up with this little gem. I will focus less on the “how” and shine a brighter light on some of the “why”.

  • Why should I use a constant instead of a variable whenever possible?
  • Why are there implicitly unwrapped optionals in Swift and why are they so darn confusing?
  • Why should I use Swift if I can still use Objective-C and love it so?

I will also occasionally take you behind the curtain and explore some of the things that make Swift tick.

  • What is CIL, LLVM IR, and why should I care?
  • Is Swift really faster then Objective-C and how did they do that?

Most importantly, I want to help you to learn to “think in Swift”. No one likes to be the foreigner in a strange land speaking the language in that “not quite right” sort of way. The Python community uses the term “pythonic” to refer to code written the “right way” and not in a way that makes them say, “Look, how cute, another C programmer trying to write Python code”. Looking like a Swift native speaker will require you to think different at times (wouldn’t want it any other way) but it will hopefully be a rewarding and enjoyable experience. Swiftic? Swiftonic? Swifty? I think I’ll stick with “thinking in Swift”.

If you’d like to dive right in with a discussion about the different ways to write Swift and the Swift compiler itself, feel free to move on to Part II. If not, stick around and take a brief journey with me through some of the relevant history leading up to the announcement of Swift.

Some Background

NeXTIn 1996, Apple acquired NeXT Computer, Inc. As a result of that deal, Apple ended up with new leadership (Steve Jobs – again), a new operating system (OS X), and a programming language (Objective-C).

Objective-C was actually developed in the early 1980s and selected as the main language for the NeXT OS in 1988. The Foundation and AppKitsoftware development frameworks were also initially developed at NeXT and this is why many class names begin with the letters “NS” for NeXTstep.

While some developers really do like Objective-C (including yours truly), others have called it everything from an outdated language to an abomination. In truth, the developers at Apple were playing the hand they were dealt and they made the best of it by adding new modern language features on a regular basis:

  • Properties
  • Dot syntax
  • Blocks
  • Automatic Reference Counting (ARC)
  • Collection literals

LLVMA significant step in the evolution of Objective-C at Apple was the move from the GCC compiler to the LLVM compiler infrastructure and the Clang compiler front end. The initial design and implementation of LLVM was the work of Chris Lattner while a research assistant at the University of Illinois at Urbana-Champaign (early 2000).

As an interesting aside, Chris worked as a research intern for Microsoft Research during the summer of 2004 where he built an experimental bridge between the Microsoft compiler and the LLVM compiler allowing LLVM to compile and run .NET code.

In 2005, Chris was hired by Apple and began the process of preparing LLVM for use in Apple products. Eventually, enough of the pieces were in place for a more significant change.

In July of 2010, Chris began work on a new programming language (Swift) that could take maximum advantage of the LLVM infrastructure. Swift became a major focus of the Apple Developer Tools group in July 2013 and was officially unveiled to the public in June 2014.


Author: Jason Bell, Accelebrate’s Director of Technology and senior instructor.

Accelebrate offers private Swift training and iOS training and for groups and instructor-led online Swift classes for individuals.


Written by Jason Bell

Jason Bell

Jason is Accelebrate's Director of Technology where he ensures the smooth and effective running of Accelebrate's IT infrastructure to support the organization's continued growth. Jason also is a trainer specializing in Computer software design and development, C/C++, Microsoft .NET, Apple OS X, iOS (Objective-C and Swift), IIS, and more.
  



Contact Us:

Accelebrate’s training classes are available for private groups of 3 or more people at your site or online anywhere worldwide.

Don't settle for a "one size fits all" public class! Have Accelebrate deliver exactly the training you want, privately at your site or online, for less than the cost of a public class.

For pricing and to learn more, please contact us.

Contact Us Train For Us

Toll-free in US/Canada:
877 849 1850
International:
+1 678 648 3113

Toll-free in US/Canada:
866 566 1228
International:
+1 404 420 2491

925B Peachtree Street, NE
PMB 378
Atlanta, GA 30309-3918
USA

Subscribe to our Newsletter:

Never miss the latest news and information from Accelebrate:

Microsoft Gold Partner

Please see our complete list of
Microsoft Official Courses

Recent Training Locations

Alabama

Huntsville

Montgomery

Birmingham

Alaska

Anchorage

Arizona

Phoenix

Tucson

Arkansas

Fayetteville

Little Rock

California

San Francisco

Oakland

San Jose

Orange County

Los Angeles

Sacramento

San Diego

Colorado

Denver

Boulder

Colorado Springs

Connecticut

Hartford

DC

Washington

Florida

Fort Lauderdale

Miami

Jacksonville

Orlando

Saint Petersburg

Tampa

Georgia

Atlanta

Augusta

Savannah

Idaho

Boise

Illinois

Chicago

Indiana

Indianapolis

Iowa

Ceder Rapids

Des Moines

Kansas

Wichita

Kentucky

Lexington

Louisville

Louisiana

Banton Rouge

New Orleans

Maine

Portland

Maryland

Annapolis

Baltimore

Hagerstown

Frederick

Massachusetts

Springfield

Boston

Cambridge

Michigan

Ann Arbor

Detroit

Grand Rapids

Minnesota

Saint Paul

Minneapolis

Mississippi

Jackson

Missouri

Kansas City

St. Louis

Nebraska

Lincoln

Omaha

Nevada

Reno

Las Vegas

New Jersey

Princeton

New Mexico

Albuquerque

New York

Buffalo

Albany

White Plains

New York City

North Carolina

Charlotte

Durham

Raleigh

Ohio

Canton

Akron

Cincinnati

Cleveland

Columbus

Dayton

Oklahoma

Tulsa

Oklahoma City

Oregon

Portland

Pennsylvania

Pittsburgh

Philadelphia

Rhode Island

Providence

South Carolina

Columbia

Charleston

Spartanburg

Greenville

Tennessee

Memphis

Nashville

Knoxville

Texas

Dallas

El Paso

Houston

San Antonio

Austin

Utah

Salt Lake City

Virginia

Richmond

Alexandria

Arlington

Washington

Tacoma

Seattle

West Virginia

Charleston

Wisconsin

Madison

Milwaukee

Alberta

Edmonton

Calgary

British Columbia

Vancouver

Nova Scotia

Halifax

Ontario

Ottawa

Toronto

Quebec

Montreal

Puerto Rico

San Juan

© 2013-2019 Accelebrate, Inc. All Rights Reserved. All trademarks are owned by their respective owners.