Apple introduced new programming language - Swift

Swift is a multi-paradigm, compiled programming language developed by Apple for iOS and OS X development. Introduced at Apple's developer conference WWDC 2014, Swift is designed to replace Objective-C, Apple's object-oriented language, while working with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C code written for Apple products.

Swift is intended to be more resilient against erroneous code. It is built with the LLVM compiler included in Xcode 6 beta, and uses the Objective-C runtime, allowing Objective-C, Objective-C++ and Swift code to run within a single program.

The Swift Programming Language, a free 500-page manual, was also released at WWDC.


How Swift differs from Objective-C
  1. Statements do not need to end with a semicolon (';'), though they may be used to allow more than one statement on a line
  2. Header files are not required
  3. Comments of the form /* ... */ can be nested, allowing blocks of code to be easily commented out.
  4. Strong typing
  5. Type inference
  6. Generic programming
  7. Functions are first-class objects.
  8. Operators can be redefined for classes (operator overloading), and new operators can be created.
  9. Strings fully support Unicode. Most, but not all, Unicode characters can be used in Swift language names.
Example code

// this is a single line comment using two slashes

/* this is also a comment,
   but written over multiple lines */

// Swift variables are declared with "var" followed by a name, a type, and a value
var explicitDouble: Double = 70

/// if the type is omitted, Swift will infer it from the variable's initial value
var implicitInteger = 70
var implicitDouble = 70.0

// the "let" keyword defines a constant, which may also be implicitly typed
let numberOfApples = 3
let numberOfOranges = 5
let appleSummary = "I have \(numberOfApples) apples."
let fruitSummary = "I have \(numberOfApples + numberOfOranges) pieces of fruit."

// code can be placed anywhere, making it global within the namespace
println("Hello, world")

// define a dictionary with four items, each with a person's name and age
let people = ["Anna": 67, "Beto": 8, "Jack": 33, "Sam": 25]

// now we use Swift's flexible enumerator system to extract both values in a single loop
for (name, age) in people {
    println("\(name) is \(age) years old.")
}

// methods and functions are declared with the "func" syntax
// note the use of parameter naming, and the return type specified with ->
func sayHello(personName: String) -> String {
    let greeting = "Hello, " + personName + "!"
    return greeting
}

// prints "Hello, Jane!"
println(sayHello("Jane"))

Comments

3 Responses to "Apple introduced new programming language - Swift"

Unknown said... May 18, 2017 at 9:54 AM

Yeah....now apple is introducing Augmented Reality also...

Eboggler said... July 1, 2017 at 8:54 AM

Hello admin your blog seems very attractive and such a nice post that you have shared with us-
You may take a look for Latest Technology News stories and new Technology Updates with Eboggler here you can get all latest news on technology, tech news, technology headlines.

Online Tips said... April 27, 2019 at 10:51 AM

pcreviewer.org website is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon properties including, but not limited to, amazon, endless, myhabit, smallparts, or amazonwireless. The Website Also Earns from Viglink Affiliate.
PC Reviewer

Post a Comment

Labels