Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create an iOS liveView in Xcode 8/Swift 3 [duplicate]

I can't figure out how to create and display a live view in an Xcode 8/Swift 3 Playground. If Apple has comprehensive documentation on playgrounds and live views, I can't find it, and all my searching online reveals either tutorials on Xcode 7 or the new iPad playgrounds. The few examples I have found set up Mac OS views, which is not what I want (I work mostly in iOS, so the code I want to test out is iOS code, dealing with iOS view hierarchies.)

Can somebody give me the bare minimum setup to create a live view and install views into it from an Xcode 8 playground?

Then, can somebody point me to some good documentation on playgrounds, and how you configure and use them?

like image 599
Duncan C Avatar asked Nov 06 '16 13:11

Duncan C


1 Answers

It works like this:

import UIKit
import PlaygroundSupport

let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
view.backgroundColor = UIColor.red

PlaygroundPage.current.liveView = view

Unfortunately I'm not aware of a good documentation. But I believe there is a book by Erica Sadun about Playgrounds.

like image 86
dasdom Avatar answered Sep 21 '22 16:09

dasdom