Swift first glance ---- Playground

Source: Internet
Author: User

Playground is introduced in wwdc2014 by SWIFT. It is literally understood that playground is the playground. In swift, this "Playground" can write code while previewing the effect to realize "What you see is what you write", which makes it self-evident for programmers, compare two images:




Is it cool to simplify the process from step 6 to step 2? In addition to cool, playground can be used in actual development. It works well in two places: it is used to quickly preview the interface control effect and debug complex algorithms.

Now let's get some dry stuff,

Preview imageview

 
Let imagenames = [nsimagenameuser, nsimagenameuseraccounts, nsimagenameusergroup] Let images = imagenames. map {nsimage (named: $0)}; imageslet image = images [0] Let imageview = nsimageview (frame: nsrect (X: 0, Y: 0, width: 512, height: 512) imageview. image = imageimageview. imagescaling =. imagescaleproportionallyupordown

Preview tableview

Import uikitvar STR = "Hello, playground" class datasource: nsobject, uitableviewdatasource {func tableview (tableview: uitableview !, Numberofrowsinsection section: INT)-> int {return 4} func tableview (tableview: uitableview !, Cellforrowatindexpath indexpath: nsindexpath !) -> Uitableviewcell! {Let ROW = indexpath. Row let style = uitableviewcellstyle. fromraw (ROW) Let cell = uitableviewcell (style: style !, Reuseidentifier: nil) // Let cell = uitableviewcell (style :. default, reuseidentifier: nil) cell. textlabel. TEXT = "text1" If let detailtextlabel = cell. detailtextlabel {detailtextlabel. TEXT = "detail text"} return cell} Let DS = datasource () Let tableview = uitableview (frame: cgrect (X: 0, Y: 0, width: 320, height: 240), style :. plain) // Let tableview = uitableview (frame: cgrectmake (0.0, 0.0, 320.0, 240.0), style :. plain) tableview. datasource = dstableview. reloaddata ()


Data Types supported by Playground:


Limitations of playground:

1. The playground file cannot be directly used in the project, but the code can be copied and pasted into the project.



Q &

1. Failed to import uikit.

Enter in playground

 
Import uikit
The "no such module uikit" error occurs. The solution is to set platform to IOS (OS X by default)

Open File inspector, as shown in settings



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.