Create arrays and dictionaries using brackets ([])
var shoppingList = ["catfish", "water", "tulips", "blue paint"]
shoppingList[1] = "bottle of water"
var occupations = [
"Malcolm": "Captain",
"Kaylee": "Mechanic",
]
occupations["Jayne"] = "Public Relations”
Apple’s programming language Swift
Tuesday, 3 June 2014
Swift Programming Language Tutorial Two
Simple Values:
Use "let" to make a constant.
Use "var" to make a variable.
var variableOne = 30
variableOne = 165
let constantOne = 12
Remember you don't have to write the type of variable explicitly. But if you do here is how to write:
let implicitInteger = 70
let implicitDouble = 70.0
let explicitDouble: Double = 70
But if you need to convert a value to a different type, you must then explicitly make an instance of the desired type.
let label = "This is the integer value:"
let integerValue = 94
let theString = label + String(integerValue)
From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/gb/jEUH0.l
Use "let" to make a constant.
Use "var" to make a variable.
var variableOne = 30
variableOne = 165
let constantOne = 12
Remember you don't have to write the type of variable explicitly. But if you do here is how to write:
let implicitInteger = 70
let implicitDouble = 70.0
let explicitDouble: Double = 70
But if you need to convert a value to a different type, you must then explicitly make an instance of the desired type.
let label = "This is the integer value:"
let integerValue = 94
let theString = label + String(integerValue)
From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/gb/jEUH0.l
Swift Programming Language Tutorial One
Lets start with the programming tradition, printing "Hello, world!"
println("Hello, world")
The above line is a complete line of code in swift.
In swift:
println("Hello, world")
The above line is a complete line of code in swift.
In swift:
- You don't need to import a seperate library for input/output or string handeling.
- You don't need a main funtion
- You dont need to write semicolons at the end of every statement.
- How awesome is that! :)
What is swift?
“Swift is a new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun. Swift’s clean slate, backed by the mature and much-loved Cocoa and Cocoa Touch frameworks, is an opportunity to reimagine how software development works.
Swift has been years in the making. Apple laid the foundation for Swift by advancing our existing compiler, debugger, and framework infrastructure. We simplified memory management with Automatic Reference Counting (ARC). Our framework stack, built on the solid base of Foundation and Cocoa, has been modernized and standardized throughout. Objective-C itself has evolved to support blocks, collection literals, and modules, enabling framework adoption of modern language technologies without disruption. Thanks to this groundwork, we can now introduce a new language for the future of Apple software development.
Swift feels familiar to Objective-C developers. It adopts the readability of Objective-C’s named parameters and the power of Objective-C’s dynamic object model. It provides seamless access to existing Cocoa frameworks and mix-and-match interoperability with Objective-C[…]”
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/gb/jEUH0.l
Swift has been years in the making. Apple laid the foundation for Swift by advancing our existing compiler, debugger, and framework infrastructure. We simplified memory management with Automatic Reference Counting (ARC). Our framework stack, built on the solid base of Foundation and Cocoa, has been modernized and standardized throughout. Objective-C itself has evolved to support blocks, collection literals, and modules, enabling framework adoption of modern language technologies without disruption. Thanks to this groundwork, we can now introduce a new language for the future of Apple software development.
Swift feels familiar to Objective-C developers. It adopts the readability of Objective-C’s named parameters and the power of Objective-C’s dynamic object model. It provides seamless access to existing Cocoa frameworks and mix-and-match interoperability with Objective-C[…]”
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/gb/jEUH0.l
Subscribe to:
Posts (Atom)