Getting Started with swift development diagrams

Source: Internet
Author: User
Tags time and date

Tag: Sum code RAW Branch produces TPS pop and display

"The Analects of Confucius Weiling" has a classic dialogue: "Son Gong for benevolence." Zi Yue: 工欲善其事, its prerequisite.

......』。

For a program ape, a good tool does not mean that it will produce high-quality code. But good tools are also self-evident in their role in improving development efficiency. Want to do iOS development with Swift. The only option is Xcode6, children's shoes can be obtained from the following site Xcode6 download links, on this page can also find Swift's official books, example code and video.

Xcode6 Download: https://developer.apple.com/swift/resources/

Next we are able to start creating a project Swift01, as seen in:








The above see is the starter program "Hello, World".

The next thing to do is to be able to build the entire project or simply execute the project and view the results in the console, as seen in:


All right, it's just so easy. But what we're going to talk about is not as simple as Hello world, so let's get a sense of Swift with the following code.

Import Foundationvar A:int = 123//Define a variable of type Int alet b = 321//define constant B as intprintln by type ("\ (a) + \ (b) = \ (A + b)")/ /the \ () in the string can put variables, constants, expressions//output: 123 + 321 = 444//from 1 to 100 sum var = 0for var i = 1; I <= 100;  ++i {//For loop sum + = I}println ("sum = \ (sum)")//output: sum = 5050for ch in "Hello" {// For each character of Hello, loop println (ch)}var randomage = arc4random ()% 50//Call the function in Foundation to generate a random number of print ("You" re \ (randomage) ye ars-old! ") var myage:uint32 = 33;if randomage > MyAge {//IF-ELSE branch structure println (" older Than me! ")} else {println ("Younger than me!")}  Based on the current system time display prompt//[spit slot] time and date operation in the Apple programming language is really troublesome var currdate = NSDate ()//Create Time Date Object var MyCal = Nscalendar (Calendaridentifier:nsgregoriancalendar)//Create calendar object (Gregorian Gregorian calendar)///The following two lines of code take out the hourly portion of the current time date var MyComp: nsdatecomponents = Mycal.components (Nscalendarunit.hourcalendarunit, fromdate:currdate) var hour = MyComp.hourswitCh Hour {Case 7, 8:println ("Enjoy Your breakfast!") Case one, 13:println ("A Good lunch!") Case, 19:println ("It's a good time for dinner!") Default:println ("Do something to make yourself happy.")} var myarray:int[] = [12, 35, 96, 47, 5, 23, 68, 3, 68]myarray + = [5], 81]PRINTLN (myArray)//output: [+] 2, 81]//defines the function that finds the largest and smallest elements in the array//Declaration function keyword is func, findmaxandmin is the function name//functions name () is the reference list, whose parameters are an array of type int,//The return value is a tuple (including multiple data compound values ), including the return value of two integers//functions is the Func findmaxandmin (x:int[])---(int, int) {var min:int = x[0] var max:i after the function's list of functions, which specifies its type NT = x[0] for var index = 1; Index < X.count; ++index {if x[index] > max {max = X[index]} else if X[index] < min {min = X[index]}} retur N (min, max)}println (Findmaxandmin (MyArray))//Output: (5, 96)//define a dictionary type (key-value pair mapping) var mydic = [1001: "Apple", 1002: "Banana",   1003: "Grape"]for (no, name) in Mydic {println ("key = \ (no), value = \ (name)")}mydic[1003] = "Strawberry" println (mydic)       Output: [1001:apple, 1002:banana, 1003:strawberry]var myFruit1 = mydic[1002]//Bananavar myFruit2 = mydic[2001] Nilif MyFruit2 = = Nil {println (myFruit1)}else {println (myFruit2)}//the function as a function's parameter (lambda function) Func repeat (count:int    , Callback: (), ()) {for i in 0..count {callback (); }}//Call repeat function output 10 times Hello, World!repeat ({println ("Hello, world!")})

Getting Started with swift development diagrams

Related Article

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.