Skip to content

Instantly share code, notes, and snippets.

Avatar
shipping

Ahmed Bouchfaa ahbou

shipping
View GitHub Profile
View Observable.swift
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 / gist:44edfb02a1facbd3307d06f28996b3d9
Created Nov 27, 2020 — forked from zetachang/gist:4111314
Instruction on adding a Acknowledgements Settings.bundle
View gist:44edfb02a1facbd3307d06f28996b3d9
  • 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>
	<array>
@ahbou
ahbou / URLCacheTest.swift
Created Nov 12, 2020 — forked from steipete/URLCacheTest.swift
Using URLCache with download tasks (NSURLCache & NSURLSessionDownloadTask)
View URLCacheTest.swift
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 / Log.swift
Created Jun 22, 2020
Swift logger with emoji
View Log.swift
//
// Log.swift
//
//
import Foundation
class Log {
class func msg(message: String,
functionName: String = #function, fileNameWithPath: NSString = #file, lineNumber: Int = #line ) {
View UIView+RSKeyboardLayoutGuide.swift
//
// UIView+RSKeyboardLayoutGuide.swift
// RSTouchUIKit
//
// Created by Daniel Jalkut on 12/23/18.
//
import UIKit
// Extends UIView to expose a keyboardLayoutGuide property that can be used to tie a view controller's content
@ahbou
ahbou / UIWindow+Extension.swift
Created Jun 1, 2018
Animate UIWindow rootViewController switch
View UIWindow+Extension.swift
extension UIWindow {
func setRootViewController(_ rootViewController: UIViewController?, animated: Bool) {
guard let viewContoller = rootViewController else {
self.rootViewController = rootViewController
return
}
var snapShotView: UIView?
@ahbou
ahbou / HUD.swift
Last active Oct 28, 2019
Dead Simple HUD implementation in swift with a title and an Acitivity indicator
View HUD.swift
import UIKit
class HUD: UIView {
private lazy var backView: UIView = UIView(frame: bounds)
private let activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView(style: .whiteLarge)
private lazy var titleLabel: UILabel = {
let title = UILabel()
title.font = UIFont.boldSystemFont(ofSize: 16)
@ahbou
ahbou / WavPlayer.swift
Created Oct 12, 2017
Play .wav file in Swift
View WavPlayer.swift
let ringtonePath = URL(fileURLWithPath: Bundle.main.path(forResource: "sound", ofType: "wav")!)
do {
let ringtonePlayer = try AVAudioPlayer(contentsOf: ringtonePath)
try AVAudioSession.sharedInstance().setActive(true)
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)
ringtonePlayer.volume = 1.0
ringtonePlayer.play()
} catch {
print("Failed to initialize audio player \(error.localizedDescription)")
@ahbou
ahbou / ComposeView.swift
Last active Jul 12, 2019
iPhone X InputAccessoryView Fix
View ComposeView.swift
//
// ComposeView.swift
import UIKit
class ComposeView: UIView {
// ........
// Other layout code and methods
// ........
@ahbou
ahbou / Storage.swift
Created Sep 17, 2017 — forked from saoudrizwan/Storage.swift
Helper class to easily store and retrieve Codable structs from/to disk. https://medium.com/@sdrzn/swift-4-codable-lets-make-things-even-easier-c793b6cf29e1
View Storage.swift
import Foundation
public class Storage {
fileprivate init() { }
enum Directory {
// Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the <Application_Home>/Documents directory and will be automatically backed up by iCloud.
case documents
You can’t perform that action at this time.