New Programming Language: Swift

Is Swift really as easy as it sounds?

At WWDC ’14, Apple announced a new programming language called Swift. Apple claims that the new language is more modern, safe, fast, and powerful. This new language is available to developers through Xcode 6 Beta, but this fall it will be available to everyone who owns a mac via Mac AppStore.

swift-screenshot_2x
This is a picture of the playground in which the language can be experimented with via Xcode 6. Courtesy of Apple Inc.

This is an easy example:

var name: String = "Pugi"
println("Hello! My name is \(name)")

In this example, I am calling a variable (var) called name, predefining it as a String (text), and setting it equal to "Pugi" in this case. Then, I am telling the computer to print a line (println) of text with the name variable that I made.

This is another example:

class animal {
    var name: String = "defName"
    var age: Int = 0
    func getInfo() -> String {
        return "This dog is named \(name), and is \(age) years old."
    }
}

var myDog = animal()
myDog.name = "Leo"
myDog.age = 3
myDog.getInfo()

In this example, I created a class called animal and made a variable called myDog that inherits the variables and function from the class. First, I defined the class called animal. Inside the class, I gave variables to the class to give specifications to my class and I created a function called getInfo that returns a summary of the animal. After I created this class, I made a variable (var) called myDog outside of the class, predefined it as a string, and set it equal to the animal class. This tells the computer that myDog is an animal (from the class that I made). The variables and function, from the class animal should be defined to give myDog a more detailed variable. So, I set the name of myDog to "Leo", set the age of the myDog to 3, and passed the function getInfo. When I finally passed the function getInfo, the computer returned "This dog is named Leo, and is 3 years old.".

Is the new language a good starting point for new developers? Yes! Many new iOS developers can start learning Swift as their first language. Understanding the fundamentals are key for developing great apps using Swift. In the iBooks store Apple has released a book that teaches the new syntax of the language. Also there are many online tutorials that explain how to use Swift to build awesome apps. Swift is a great way for beginners to learn how to develop powerful iOS and OS X apps.

Advertisements

2 thoughts on “New Programming Language: Swift

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s