Skip to content

Instantly share code, notes, and snippets.


Amir Abbas Mousavian amosavian

View GitHub Profile
View RedisValueHelper.swift
// RedisValueHelper.swift
// Created by Amir Abbas Mousavian on 01/01/2020.
import Foundation
import Vapor
import NIO
View Devices.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
<string>iPhone 5 (GSM)</string>
<string>iPhone 5 (GSM+CDMA)</string>
<string>iPhone 5C (GSM)</string>
amosavian / UIKitEmbed.swift
Last active Aug 18, 2019
Helper methods to ease usage of auto-layout
View UIKitEmbed.swift
extension UIViewController {
enum LayoutGuide {
case none
case layoutMargin
case readableContent
case safeArea
func embed(_ viewController: UIViewController, into: UIView? = nil, inset: UIEdgeInsets = .zero, edges: UIRectEdge = .all,
guide: UILayoutGuide? = nil, priorities: UIView.EdgePriorities = .init()) {
View CodableMagic.swift
struct Bill: Codable {
let b: String
let c: String
struct B2: Codable {
enum CodingKeys: String, CodingKey { case a }
let bill: Bill
let a: Int
View NSCoder.swift
extension NSCoder {
func encode<T: RawRepresentable>(_ object: Any?, forKey key: T) where T.RawValue == String {
switch object {
case let object as Bool:
encode(object, forKey: key.rawValue)
case let object as Int32:
encode(object, forKey: key.rawValue)
case let object as Int64:
encode(object, forKey: key.rawValue)
case let object as Float:
amosavian / App-Bridging-Header.h
Last active Feb 11, 2019
Workaround OneSignal embargo
View App-Bridging-Header.h
/// Add these lines to your app bridging header
#import <OneSignal/OneSignal.h>
#import "OneSignalTweak.h"
View swift-bug.swift
protocol A {
func foo() -> Int
extension A {
func foo() -> Int {
return 10
View URLSession.swift
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
if let response = task.response as? HTTPURLResponse, response.statusCode >= 400 {
// Workaround a CFNetwork bug which cause a write posix error.
// Invalidates session and start tasks again.
if let error = error as? POSIXError, error.code == .ENOENT {
View EmojiFlag.swift
extension String {
private func regionalIndicatorSymbol(unicodeScalar: UnicodeScalar) -> UnicodeScalar? {
let uppercaseA = UnicodeScalar("A")!
let regionalIndicatorSymbolA = UnicodeScalar("\u{1f1e6}")!
let distance = unicodeScalar.value - uppercaseA.value
return UnicodeScalar(regionalIndicatorSymbolA.value + distance)
public var emojiFlag: String {
return self.uppercased(){
amosavian /
Last active Dec 12, 2017
Target platform condition Proposal for Swift

Target platform condition