Skip to content

Instantly share code, notes, and snippets.

@sohayb
sohayb / ArrayDeepCopy.swift
Last active October 13, 2023 07:58
Array deep copy in Swift
//Protocal that copyable class should conform
protocol Copying {
init(original: Self)
}
//Concrete class extension
extension Copying {
func copy() -> Self {
return Self.init(original: self)
}
@quangtqag
quangtqag / AppDelegate.swift
Last active August 31, 2023 02:15
Make app always call applicationWillTerminate
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