Skip to content

Instantly share code, notes, and snippets.

@vialyx
Last active November 20, 2018 18:31
Show Gist options
  • Save vialyx/9e2f8947a6bda86a119e10e48ec22a51 to your computer and use it in GitHub Desktop.
Save vialyx/9e2f8947a6bda86a119e10e48ec22a51 to your computer and use it in GitHub Desktop.
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
final class MyViewController: UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
let label = UILabel()
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
label.text = "Hello World!"
label.textColor = .black
view.addSubview(label)
self.view = view
}
override func viewDidLoad() {
super.viewDidLoad()
// Setup self as oberver for UIApplication.didBecomeActiveNotification notification name
NotificationCenter.default.addObserver(self,
selector: #selector(appDidBecomeActive),
name: UIApplication.didBecomeActiveNotification, object: nil)
}
// That function runs when app will be active
@objc private func appDidBecomeActive() {
print("UIApplication is active now")
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment