Spy on the different HelloWorld of Swift programming

Source: Internet
Author: User

The original: A glimpse into the different helloworld of Swift programming

Starting today, the release of some of the swift language, although currently in the company's project development Objective-c is still the main force of iOS development, but in the near future, Swift will become the new darling of iOS development. So it is necessary to play Swift on the xcode6.0+ version of Playground. In the next blog post, I'm going to summarize what I've learned in the book, "Getting Started with Swift programming" (published in Tsinghua University Press). In translating this book, he is a translator, but also a reader, after reading the original feeling learned a lot of new things, let his thinking more open.

To learn a new programming language, code is indispensable. At the time of translation, oneself is also in coding, the book each piece of code to knock over. Learn to program, hands is the key to avoid the eye master of the situation. In writing code, do not step-by-step to coding, to learn to think, learn to extrapolate, learn the expansion of self. For example, in a demo, you can try to modify something, then predict what kind of results you will get, and then verify that you are consistent with your own predictions and find out why. In fact, growth in the problem is the fastest, each problem is the solution of self-improvement process. Some things need talent, but some things still need to work hard, who is born is technology Daniel ~ Most of Daniel is not from eating cabbage grew up? Ok no nonsense, "an idle youth, long University programming", cut into today's topic, to spy on the swift language.

First explain the compilation environment: Xcode6.3, of course, Xcode6.0 later versions support the Swift language, then we can in Apple specifically for the swift design of the playground to do whatever the swift language to engage in.

  First, create your own Swift project.

First create a Swiftdemo project, right, the steps are as follows:

1. How to open Xcode I'm not going to pull it off. First create a new project, as follows:

  

2. Then select Ios->application->single View Application Click Next

    

3. Type productname:swiftdemo,organiztion name, Organization identifier generally for your company domain name in reverse order such as Com.cnblogs.lizelu, the development language select Swift, Device here we choose the iphone. Then click Next and if you want to use CoreData to store the data in your project, you can choose User Core data.

    

4. The following is the project we created, the swift language file suffix is swift, it is not in the. h and. m files like Objective-c

    

  Two. How to implement HelloWorld on the project created above.

1. Of course, why don't you have storyboard? Add a Label:helloworld on Viewcontroller and set the style, then add a button to the label and add the appropriate constraint as shown below.

        

2. For our button to associate the corresponding click event, connection Select Action, and then take a name (Taphelloworldbutton), the type is selected as UIButton, the event is selected as Touch up Inside, Click Connect. At this point we have a click event associated with the button.

      

3. The next thing to do when you click on the button: Click on an alter, the name of the box is Hello, there is a button called OK, the above message is "Hello Swift World".

      

4. The next exciting moment comes, let's run our Swiftdemo project (you can debug with a real machine, or you can use simulator debugging), the following is the effect of running out, click on Hello world! will pop up our definition of the prompt box.

      

  Three, summary

So far, you've learned how to create a swift language project, and how to implement the Hello World UI, and how to associate the button with the corresponding event. Now that you have tapped into the gates of Swift world, let us take a dip in the swift world in the following days, if there is a problem with the iOS development can be in the message to Exchange learning, or join the QQ Exchange group above, common progress and improve. Look forward to some of the following swift tutorials, and finally thank Tsinghua Press for the translation of the "Introduction to Swift Programming Classics".

  

Spy on the different HelloWorld of Swift programming

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.