Skip to content

Instantly share code, notes, and snippets.

View ahbou's full-sized avatar
shipping

Ahmed Bouchfaa ahbou

shipping
View GitHub Profile
@ahbou
ahbou / URLCacheTest.swift
Created November 12, 2020 08:23 — forked from steipete/URLCacheTest.swift
Using URLCache with download tasks (NSURLCache & NSURLSessionDownloadTask)
import Foundation
import os.log
class URLCacheTest {
let logger = Logger(subsystem: "URLCacheTest", category: "main")
// HTTP HEADERS:
// Date: Wed, 04 Nov 2020 11:13:24 GMT
// Server: Apache
// Strict-Transport-Security: max-age=63072000; includeSubdomains; preload
@ahbou
ahbou / gist:44edfb02a1facbd3307d06f28996b3d9
Created November 27, 2020 08:53 — forked from zetachang/gist:4111314
Instruction on adding a Acknowledgements Settings.bundle
  • To add Settings.bundle in Xcode. Command N and in Resource, choose Settings Bundle .
  • Open Root.plist in source code, paste the code below to replace it,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>PreferenceSpecifiers</key>
	
@ahbou
ahbou / Observable.swift
Created December 9, 2020 16:58
Observable
import Foundation
class Observable<T>: NSObject {
private var subscriptions: Atomic<[WeakBox<Subscription>]> = Atomic([])
fileprivate func fire(_ payload: T) {
let targets = subscriptions.modify { value -> [Subscription] in
value = value.filter { $0.value != nil }
return value.compactMap { $0.value }
@ahbou
ahbou / ProfileViewController.swift
Last active March 17, 2021 11:35
CoreData discard changes
import UIKit
class ProfileViewController: UIViewController {
/// First create a throwable child context for editing the Profile
private lazy var writeContext: NSManagedObjectContext = {
let result = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
result.automaticallyMergesChangesFromParent = true
result.performAndWait {
// Our main parent context
struct Overlay: View {
@State private var showLive = true
@State private var isAnimationSlowed = false
var body: some View {
VStack {
Spacer()
HStack {
Spacer()