Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does swift playground support UIKit?

I tried to create a UILabel in playground but failed. Does playground only support OS X development for now?

like image 946
bydsky Avatar asked Jun 03 '14 07:06

bydsky


People also ask

What type of code does Swift playground use?

But then what? Swift Playgrounds teaches concepts and uses real Swift structure, but it's not real code. It doesn't make an app, it just guides Byte around and solves puzzles. Swift doesn't have a real command called collectGem() after all.

Is Swift Playgrounds a good way to learn to code?

Swift Playgrounds is a wonderful introduction to programming. It introduces imperative logic, functions, methods, loops, and many of the marvelous APIs that are available to iOS developers.

Can you make games in Swift playground?

We can design and build standalone apps, but currently, there is no support for back-end capabilities.


2 Answers

YES, it does!

File: New > File... > iOS > Source > Playground

import UIKit let lbl = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 100)) lbl.text = "Hello StackOverflow!" 

Then, save the file. (Or manually run it.) This will trigger the Playground to interpret UI related things. At this point, the word "UILabel" should appear on the right-hand side.

ios playground quickview

Now, to actually view what you've done, you've got to click on the "Quick View" eye on the right, or the white circle to open it in Assistant Editor:

Here's a screenshot of some basic things with UIImage working, etc. ios playground example

(EDIT: minor text update to current CGRect syntax -- But, screenshots still show old syntax.)

like image 108
MechEthan Avatar answered Sep 30 '22 15:09

MechEthan


Edited@2014-11-13: It seems the new xcode 6 had fixed this.

NO, It doesn't. But it's worth noting that you can import UIKit.

If you want to import UIKit you cound follow this:

  1. View -> Utilities -> Show File Inspector (opt + cmd + 1)
  2. On the right side of Xcode Change “Playground Settings -> Platform” from OS X to iOS

then you could import UIKit or some module for iOS

ps. I try to create a UIImageView but it doesn't show the correct image on the right side. It seem worthless to import UIKit

like image 45
6david9 Avatar answered Sep 30 '22 16:09

6david9