I'm running a playground, Xcode 6.3 (6D543q). Therefore Swift 1.2
The Playground imports XCPlayground. I'm creating a UIView and calling XCPShowView() to have it render in the Simulator instead of in the Playground. I'm also presenting a UIAlertView the same way.
The UIAlertView appears as normal. The UIView flickers between a larger and smaller size about 5 times a second, reasonable irregularly. I've tried resizing it to meet the bounds of the screen but no luck.
Code below....
// Playground - noun: a place where people can play
import UIKit
import Foundation
import XCPlayground
XCPlayground.XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
@objc class alertHandler: NSObject, UIAlertViewDelegate {
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
if buttonIndex > 0 {
// View things....
let redRectangleFrame = CGRect(x: 0, y: 0, width: 200, height: 200)
let redRectangle = UIView(frame: redRectangleFrame)
redRectangle.backgroundColor = UIColor.redColor()
redRectangle.setTranslatesAutoresizingMaskIntoConstraints(false)
XCPShowView("Red Rectangle", redRectangle)
// Alert view things...
let recevingAlertView = alertView
let text = alertView.textFieldAtIndex(0)?.text
println("\(text!)")
println("Button \(buttonIndex)")
}
}
}
let anAlertHandler = alertHandler()
let status = "Hey there!"
let message = "Do you have a moment to talk about our Lord and Saviour, Cthulhu?"
let cancel = "Sounds wierd"
let ok = "Oooh! Yes"
let alert = UIAlertView(title: status,
message: message,
delegate: anAlertHandler,
cancelButtonTitle: cancel,
otherButtonTitles: ok)
alert.alertViewStyle = UIAlertViewStyle.PlainTextInput
alert.show()
XCPShowView("Alert", alert)
Noticed some flicker locally with a few test playground simulator examples (your example was crashing for me Version 6.3.2 (6D2105))
From this post (their animation did show up but was flickering, and overlapping)
There are some limitations and draw backs to UIKit in Playgrounds. The primary limitation is that Auto Layout has some issues when used in Playgrounds. Some constraints will cause runtime exceptions in addition to increased compile times. Hopefully future updates to Xcode will resolve this. Another draw back is the performance of Playgrounds when using XCPlayground. There can be delays as Xcode works with the iOS Simulator running behind the Playground.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With