iOS Playground doesn't show UI preview
Open the preview panel: View > Assistant Editor > Show Assistant Editor
Then in your code:
import PlaygroundSupport
PlaygroundPage.current.liveView = view
Don't forget to give your view a visible frame.
Ps: after Xcode 9, you can create a playground with default view
Swift playgrounds with UIImage
- Open the .playground file in Finder.
- Create a folder called Resources next to it.
- Add any images you want to this folder.
- In the playground press opt-cmd-1 to open the File Inspector. You should see the playground on the right. If you don't have it selected, press cmd-1 to open the Project Navigator and click on the playground file.
- Under 'Resource Path' choose 'Relative To Playground'
- Click the folder icon underneath and choose the Resources folder created earlier.
You should now have a bundle that you can use with the standard NSImage(named:"filename_without_extension"):
Note: Because Xcode will frequently overwrite the .playground folder, I recommend using this method so the resources folder isn't getting constantly deleted and re-created.
Xcode 8.3.2 playground live view rendering doesn't work
You need to enable the assistant editor to see the results.
View > Assistant Editor > Show Assistant Editor
Also see here:
iOS Playground doesn't show UI preview
Xcode 11 beta swift ui preview not showing
To preview and interact with views from the canvas in Xcode, ensure your Mac is running on Catalina MacOS.
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views
Please check apple document in the following URL
https://developer.apple.com/documentation/xcode_release_notes/xcode_11_beta_2_release_notes
Xcode 11 beta supports development with SwiftUI.
Note
Tools for SwiftUI development are only available when running on macOS
Catalina 10.15 beta.
Playground view output only shows black view
UIStackView does not draw directly to the screen, it just sets up constraints for it's arranged subviews and has those subviews draw directly to the screen. It's background color is ignored because it doesn't draw itself to the screen. To get a background color, you can add it as a subview of a UIView.
Additionally, the text labels need to have their color set to something non-black since black text rendered over black background cannot be seen. The following code should create a nice UIStackView of white text on a blue background.
import UIKit
import XCPlayground
let standardFrame = CGRect(x: 0, y: 0, width: 320, height: 480)
let rootView = UIView(frame: standardFrame)
rootView.backgroundColor = UIColor.blueColor()
let stackView = UIStackView(frame: standardFrame)
stackView.distribution = .EqualSpacing
stackView.alignment = .Center
let strings = ["Hello world", "Guten Tag", "Buenos Dias"]
strings.map { str in
let newLabel = UILabel()
newLabel.textColor = UIColor.whiteColor()
newLabel.text = str
return newLabel
}.forEach(stackView.addArrangedSubview)
rootView.addSubview(stackView)
XCPlaygroundPage.currentPage.liveView = rootView
WKWebView doesn't show on Playground
You need to specify frame explicitly (as there is no window)
PlaygroundPage.current.setLiveView(webView().frame(width: 400, height: 300))
Xcode Canvas for SwiftUI previews does not show up
You need to be on Catalina macOS version (10.15), as stated in official tutorial
Be warned: Catalina doesn't support 32-bit applications, some old apps will stop working after update.
Related Topics
Behavior Differences Between Performblock: and Performblockandwait:
Uirefreshcontrol - Pull to Refresh in iOS 7
How to Use Avsamplebufferdisplaylayer in iOS 8 for Rtp H264 Streams with Gstreamer
How to Zoom a Uiscrollview Inside of a Uicollectionviewcell
Run Repeating Nstimer with Gcd
Swift 3: Expression Implicitly Coerced from 'Uiview' to Any
Xcode 7 How to Refresh Provisioning Profiles
Avqueueplayer Playback Without Gap and Freeze
Using Core Data with Watchos 2.0
How to Animate Tab Bar Tab Switch with a Crossdissolve Slide Transition
Expanding and Collapsing Table View Cells in iOS
In Swift: Difference Between Array VS Nsarray VS [Anyobject]
How to Compare Ssl Certificates Using Afnetworking
Cross Directional Uiscrollviews - How to Modify the Scrolling Behaviour
Setting Maximum Number of Characters of 'Uitextview ' and 'Uitextfield '
Xcode 7.1 Swift 2 Unknown Class in Interface Builder File
Xcode6 Error: "No Matching Provisioning Profiles Found for Application"