What is Swift
Swift is a new programming language for iOS, watchOS, MacOS, and tvOS apps that build on the best of C & Objective-C, without of the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to more flexible, make programming easier, and more fun. Swift’s clean slate, backed by the much-loved Cocoa and Cocoa Touch frameworks and mature, is an opportunity to reimagine how software development works.
Swift is a new programming language for iOS, watchOS, MacOS, objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming more flexible, easier, and more fun. Swift’s clean slate, Cocoa Touch frameworks, is an opportunity to reimagine how software development works. Apple laid the foundation for Swift by advancing our existing compiler, and framework infrastructure. We simplified the memory management access with Automatic Reference Counting (ARC).Swift feels familiar to Objective-C developers. It provides seamless access to mix-and-match interoperability with Objective-C code existing and Cocoa frameworks.It adopts the readability of the power of Objective-C’s dynamic object model and Objective-C’s named parameters. Building from this common ground, Swift introduces many new features and unifies the object-oriented and procedural portions of the language.
Multi-paradigm, protocol-oriented, Objective – Oriented, Functional, imperative, block Structured.
Chris Lattner. And Apple Inc.
June 2, 2014, 3 years ago.
Optional and Chaining
Runtime and development, Libraries,
Debugging and other elements
In Swift, many of these basic types have been promoted to the language is core, and can be manipulated directly. For instance, strings are invisibly bridged to NSString and can now be concatenated with the + operator
var str = “Bitware”
str += ” Technologies”
print(str) //output: Bitware Technologies
Swift supports five HYPERLINK “https://en.wikipedia.org/wiki/Encapsulation(object-oriented_programming)” \o “Encapsulation (object-oriented programming)” access control levels for symbols: public, and private, open, internal, file private.
Optional and chaining
Optional types are created with the Optional mechanism—to make is an Integer that is nullable one would use a declaration similar to var optionalInteger: Optional<Int>
Swift adds the ability to add these methods using extensions, and to use HYPERLINK “https://en.wikipedia.org/wiki/Generic programming” \o “Generic programming” generic programming (generics) to implement it will be using protocol.
func toString() -> String
extension String: SupportToString
func toString() -> String
Swift combines the best of c and Objective- C. It’s ideal for creating new apps and works seamlessly with Objective – C, so it’s compatible with apps previously created in that language.
“Bitware Technologies” Printing text is easy.
e.g print(“Bitware Technologies”)
To print the value of variable inside a text, place in parenthesis, & insert a backslash just prior to the opening parenthesis
e.g print(“The value is\(myvariable)”)
The swift compiler ignores comments, which are used to include non-executable text in your code
that may be used as a reminder or a note to self. A single line comment open with two forward-slash (//).
Eg. // this is a comment
Eg. /*this is a multiline comment*/
To build an app with swift, you will need a Mac computer(OS X 10.10 or later), running the latest version of Xcode, which features a playground, a powerful tool that allows you to run swift code with easy.
Constants & variables
Constants & variable are used to associate a name (your name or welcome message) with a value (the no of 42 or the string “Hi”). A constant has a set value that cannot be changed, the value of a variable can be changed. The keyword var is used to declare a variable, and key word let use to declare constant.
Eg. var a = 42//variable declaration
Eg. let a = 42//constant declaration
Type annotation ensures that your code is clear about the value store about constant or variable. Swifts basic types include:
Double and float: Floating point values
Bool: Boolean values
String: Textual data
Eg. var welcomemsg: String
welcomemsg = “BiteareTechonology”
An operator is a special symbol to check, change or combine values. Operator are unary, binary, or ternary
Unary operator: eg. (!b)
Binary operator: eg. (a+b)
Ternary operator : eg. (a ? b : c)
The assignment operator (a=b) initialize or update the value of a with the value of b
Eg. let b = 7
var a = 42
a = b