IOS8 development of Swift-self-study road (first day)

Source: Internet
Author: User

1.1What is Swift"Swift is a innovative new programming language for Cocoa and Cocoa Touch. Writing code is interactive and fun, the syntax is concise yet expressive, and apps run Lightning-fast. Swift is ready for your next IOS and OS X project-or for addition to your current App-because Swift code works side- By-side with Objective-c.

Swift is a new programming language for IOS and OS X apps This builds on the best of C and objective-c, without the Constr Aints 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, are 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 stacks, built on the solid base of Foundation and Cocoa, have been modernized and standardized throughout. Objective-c itself have 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 code. Building from this common ground, Swift introduces many new features and unifies the procedural and object-oriented Portio NS of the language.

Swift is friendly to new programmers. It is the first industrial-quality systems programming language, is as expressive and enjoyable as a scripting Languag E. It supports playgrounds, an innovative feature that allows programmers to experiment with Swift code and see the result s immediately, without the overhead of building and running an app.

Swift combines the best of modern language thinking with wisdom from the wider Apple engineering culture. The compiler is optimized for performance, and the language are optimized for development, without compromising on either. It's designed to scale from the "Hello, world" to the entire operating system. All the makes Swift a sound to investment for developers and for Apple.

Swift is a fantastic-to-write IOS and OS X apps, and would continue to evolve with new features and capabilities. Our goals for Swift is ambitious. We can ' t wait to see how you create with it. "
1.2Reference Books&&website

https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11

https://itunes.apple.com/us/course/developing-ios-8-apps-swift/id961180099

https://itunes.apple.com/cn/course/ios-development-in-swift/id950659946

1.3Variable (Var) or Constant (let)

What declared with var is considered mutable while Let is immutable.

var myvariable = 42myVariable = 50let Myconstant = 42____________________________let Implicitinteger = 70let Implicitdoubl E = 70.0let explicitdouble:double = 70____________________________let label = "The width is" let width = 94let Widthlabel = label + String (width) ____________________________let apples  = 3let oranges = 5let applesummary = "I have \ (apples) A Pples. "    \ () is a-to-include values in stringslet fruitsummary = "I has \ (apples+oranges) pieces of fruit."
________________________

1.4arrys and Dictionaries

Create arrays and dictionaries using brackets ([]), and access their elements by writing the index or key in brackets.

var shoppinglist = ["Apple", "banana", "water"]shoppinglist[1] = "A piece of banana" var occupations = [    "Jason": "Capt Ain ",    " Kaylee ":" Mechanic ",]occupations[" Jayne "] =" public Relations "________________________let emptyarray= [ String] () let emptydictionary= [String:flocat] () ________________________shopplinglist= []occupations= [:]__________ ______________import foundationvar arrayany: [Anyobject] = []arrayany + = [1, ","), False]arrayany.append (4.0) _________ _______________
1.5Loop

conditionals: If, switch

loops: for-in, for, while

Let Individualscore = [103, 12]var Teamscore = 0for score in Individualscore {if (Score >) {te AmScore + = 3} else {teamscore + = 1}} println (Teamscore) Teamscore//this is a simple-to-see the value O f A variable inside a playgroud._____________________________var optionalstring:string? = "Hello" optionalstring ==nilvar optionalname:string? = "Jason Wang" var greeting = "Hello!"  If let name = optionalname {greeting = "Hello, \ (name)"}_____________________________var results: [int] = []//same as var result:array[int]for i:int in 0..<100 {if I% 7 = = 0 {results.append (i)}}results________________ _____________func color (thing:string?), String?                 {if let someThing = thing {switch someThing {box Let x where X.hasprefix ("green"):                   Return "green" case "apple": Return "red" case "pineapple", "banana": Return "Yellow"            Default:return "Unknow"}} else {return nil}}color ("Apple") color ( "Green apple") Color ("banana") Color ("someThing") color (nil)

1.6Funcation

Func location (city:string) (double, double) {    var list = [        "Shanghai": (12.233, 15.332),        "Beijing": ( 33.222, 31.333)    ] [    return list[city]?? (0, 0)} Location ("Shanghai") location ("Wuhan")

1.7Closure
var odds = [1, 3, 5, 7].map ({number in 3*number}) oddsimport Foundationvar array: [UInt32] = []for _ in 0..<10 {    ar Ray.append (Arc4random_uniform (UInt32))}arraysort (&array) {$ < $}array



IOS8 development of Swift-self-study road (first day)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.