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
func applicationDidEnterBackground(application: UIApplication) { | |
// Create a pseudo background task to system call applicationWillTerminate when app enter background | |
// Default system will not call applicationWillTerminate when app enter background | |
// applicationWillTerminate only called when user close app in app switcher or some special cases of system | |
bgTask = application.beginBackgroundTaskWithExpirationHandler({ () -> Void in | |
application.endBackgroundTask(self.bgTask) | |
self.bgTask = UIBackgroundTaskInvalid | |
}) | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { () -> Void in |
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
//Protocal that copyable class should conform | |
protocol Copying { | |
init(original: Self) | |
} | |
//Concrete class extension | |
extension Copying { | |
func copy() -> Self { | |
return Self.init(original: self) | |
} |