Swift Basic Tutorial (first Swift application)

Source: Internet
Author: User

  1. Start Xcode6 from Launchpad and select "Create New Project":
    650) this.width=650; "class=" Alignnone wp-image-548 "src=" http://blog.diveinedu.net/wp-content/uploads/2014/06/new _project.png "alt=" New_project "width=" 529 "height=" "style=" margin:5px 20px 20px 0px;padding:0px;border:0px; Font-family:inherit;font-size:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height: Inherit;vertical-align:middle;height:auto; "/>


    As you can see, the Swift language project is basically the same as the OBJECTIVE-C project, except.mThe end of the objective-c source is replaced by.swiftThe end of the swift language source file.
    650) this.width=650; "class=" Alignnone wp-image-549 "src=" http://blog.diveinedu.net/wp-content/uploads/2014/06/ Source_file.png "alt=" source_file "width=" 346 "height=" 331 "style=" margin:5px 20px 20px 0px;padding:0px;border:0px; Font-family:inherit;font-size:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height: Inherit;vertical-align:middle;height:auto; "/>

2. Xcode 6 Adds a unified interface management function to the ipad and iphone in storyboard, working with Autolayou. For the sake of simplicity, disable AutoLayout first.
650) this.width=650; "class=" Alignnone wp-image-550 "src=" http://blog.diveinedu.net/wp-content/uploads/2014/06 /size_class.png "alt=" Size_class "width=" "height=" 214 "style=" margin:5px 20px 20px 0px;padding:0px;border:0px; Font-family:inherit;font-size:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height: Inherit;vertical-align:middle;height:auto; "/>

When you disable AutoLayout, the dialog box pops up to choose whether it's iphone or ipad, and we choose to develop the iphone app.
650) this.width=650; "class=" Alignnone wp-image-551 "src=" http://blog.diveinedu.net/wp-content/uploads/2014/06 /layout.png "alt=" layout "width=" 383 "height=" 213 "style=" margin:5px 20px 20px 0px;padding:0px;border:0px;font-family : Inherit;font-size:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit; Vertical-align:middle;height:auto; "/>

3. From the control bar, hold down the left mouse button and drag into a label tag, double-click the control to add text, you can modify the text color, font, alignment, etc. in the property bar on the right:
650) this.width=650; class= alignnone wp-image-552 "src=" Http://blog.diveinedu.net/wp-content/uploads/2014/06/label.png "alt=" label "width=" 439 "height=" 388 "style=" margin : 5px 20px 20px 0px;padding:0px;border:0px;font-family:inherit;font-size:inherit;font-style:inherit;font-variant: Inherit;font-weight:inherit;line-height:inherit;vertical-align:middle;height:auto; "/>

4. Click the Run button in the upper left corner of Xcode to build and run the program.
650) this.width=650; "class=" Alignnone wp-image-553 "src=" http://blog.diveinedu.net/wp-content/uploads/2014/06 /run.png "alt=" Run "width=" 537 "height=" 656 "style=" margin:5px 20px 20px 0px;padding:0px;border:0px;font-family: Inherit;font-size:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit; Vertical-align:middle;height:auto; "/>
The Run button is the Stop button and you can close the application.

5. In order to get this tag object in the code, we need to connect to the storyboard and the corresponding controller class. It is easiest to start the auxiliary editor directly to connect.
650) this.width=650; "class=" Alignnone wp-image-554 "src=" http://blog.diveinedu.net/wp-content/uploads/2014/06/ Associate_editor.png "alt=" Associate_editor "width=" 610 "height=" 324 "style=" margin:5px 20px 20px 0px;padding:0px; Border:0px;font-family:inherit;font-size:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit; Line-height:inherit;vertical-align:middle;height:auto; "/>

6. Xcode will automaticallyViewControllerGenerated inIBOutletProperties of adornmentslabel

  ViewController.swift//  SwiftApp_1////  Copyright  (c)  2014  Changsha Camp David Education . all rights reserved.//import uikitclass viewcontroller:  Uiviewcontroller {    //xcode automatically generated properties that can be seen in storyboard after @iboutlet decoration         @IBOutlet  var label : uilabel    override func  viewdidload ()  {        super.viewdidload ()          //Modifying the contents of a label label in code          self.label.text =  "Camp David Education welcomes you! "    }    override func didreceivememorywarning ()  {         super.didreceivememorywarning ()          // dispose of any resources that can be recreated.     }} 

7. The running results of the program are as follows:
650) this.width=650; "class=" Alignnone wp-image-555 "src=" http://blog.diveinedu.net/wp-content/uploads/2014/06/ First_result.png "alt=" First_result "width=" 514 "height=" 786 "style=" margin:5px 20px 20px 0px;padding:0px;border:0px; Font-family:inherit;font-size:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height: Inherit;vertical-align:middle;height:auto; "/>


Swift Basic Tutorial (first Swift application)

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.