Created
June 23, 2019 09:04
-
-
Save WingCH/6bf9fe6169f4205ab971c44e1bd8710e to your computer and use it in GitHub Desktop.
How to tell when controller has resumed from background?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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