Does swift playground support UIKit?

bydsky picture bydsky · Jun 3, 2014 · Viewed 36.7k times · Source

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

Answer

MechEthan picture MechEthan · Jun 8, 2014

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.)