Skip to content

Instantly share code, notes, and snippets.

@WingCH
Created June 23, 2019 09:04
Show Gist options
  • Save WingCH/6bf9fe6169f4205ab971c44e1bd8710e to your computer and use it in GitHub Desktop.
Save WingCH/6bf9fe6169f4205ab971c44e1bd8710e to your computer and use it in GitHub Desktop.
How to tell when controller has resumed from background?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var pasteLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
NotificationCenter.default.addObserver(self,
selector: #selector(appWillEnterForeground),
name: UIApplication.willEnterForegroundNotification,
object: nil)
}
@objc func appWillEnterForeground() {
// run when app enters foreground
@IBOutlet weak var pasteLabel: UILabel!
let pasteboardString: String? = UIPasteboard.general.string
if let theString = pasteboardString {
pasteLabel.text = theString
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment