Skip to content

Latest commit

 

History

History
110 lines (71 loc) · 3.29 KB

README.md

File metadata and controls

110 lines (71 loc) · 3.29 KB

Basic Info

Name: Swift

Creator(s): Chris Lattner, Doug Gregor, Joe Groff, Ted Kremenek and John McCall

Date: June 2, 2014

Website: swift.org

Intro

Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. and the open-source community. First released in 2014, Swift was developed as a replacement for Apple's earlier programming language Objective-C, as Objective-C had been largely unchanged since the early 1980s and lacked modern language features. Swift works with Apple's Cocoa and Cocoa Touch frameworks, and a key aspect of Swift's design was the ability to interoperate with the huge body of existing Objective-C code developed for Apple products over the previous decades.

Initially a proprietary language, version 2.2 was made open-source software under the Apache License 2.0 on December 3, 2015, for Apple's platforms and Linux. In the first quarter of 2018 Swift surpassed Objective-C in measured popularity.

Syntax

Variables in Swift are declared with the keyword var, see the example below.

var name = "Jacob"
var num = 42

print(name)
print(num)

If/Else statements in Swift are much the same as other language with brackets around the condition and curly braces around the body.

if num > 42 {
    print("The num is greater than 42.")
} else if num < 42 {
    print("The num is less than 42.")
} else {
    print("The num is 42!")
}

Swift provides a variety of loop types, a simple for loop is shown below.

var letters:[String] = ["a", "b", "c", "d", "e", "f", "g"]

for letter in letters {
    print(letter)
}

Functions in Swift are declared with the keyword func, see the example below.

func multi(no1:Int, no2:Int) -> Int {
    return no1 * no2
}

print(multi(no1: 2, no2: 20))
print(multi(no1: 3, no2: 15))
print(multi(no1: 4, no2: 30))

Classes in Swift are declared with the keyword class, see the example below.

class MarksStruct {

   var mark:Int

    init(mark: Int) {
        self.mark = mark
    }

}

class studentMarks {

    var mark1 = 300
    var mark2 = 400
    var mark3 = 900

}

let marks = studentMarks()

print("Mark1 is \(marks.mark1)")
print("Mark2 is \(marks.mark2)")
print("Mark3 is \(marks.mark3)")

Libraries

  • Awesome Swift ~ A collaborative list of awesome Swift libraries and resources.

More Info