Skip to content

Instantly share code, notes, and snippets.

Sami Samhuri samsonjs

Block or report user

Report or block samsonjs

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ContentView.swift
//
// ContentView.swift
// Layout
//
// Created by Matt Gallagher on 7/6/19.
// Copyright © 2019 Matt Gallagher. All rights reserved.
//
import SwiftUI
@samsonjs
samsonjs / InteractiveTransitionTableViewDeselection.m
Created Feb 7, 2019 — forked from smileyborg/InteractiveTransitionTableViewDeselection.m
Animate table view deselection alongside interactive transition on iOS 11
View InteractiveTransitionTableViewDeselection.m
/*
In iOS 11, interactive view controller transitions no longer scrub by setting the layer speed to zero
and changing the timeOffset. As a result of this change, implicit animations that occur in places like
-viewWillAppear: (called during an interactive transition) no longer end up “caught in” the animation.
To get the same behavior for table view row deselection as before, you can either use UITableViewController
which implements this for you, or you can implement it manually by deselecting the row in an alongside
animation for the transition (set up in -viewWillAppear: using the transition coordinator).
Here is an example implementation which correctly handles some of the more subtle corner cases:
@samsonjs
samsonjs / gist:988bd5b7ca344f43a59a36b26cf3b9c8
Last active Feb 2, 2019
Crashing bug with DateComponentsFormatter on iOS 12
View gist:988bd5b7ca344f43a59a36b26cf3b9c8
When called during launch with nil calendar and abbreviated units, DateComponentsFormatter.string(from:)
crashes attempting to call -[__NSCFString locale].
Area:
Foundation
Summary:
Due to rdar://problem/44835278 we're using DateComponentsFormatter with its calendar property set to nil
to force it to use the en_US_POSIX locale, since we can't set the locale directly. The unitsStyle
@samsonjs
samsonjs / Optional+or.swift
Created Oct 6, 2017
A hack to improve compile times by avoiding the nil-coalescing operator (??)
View Optional+or.swift
extension Optional {
func or(_ defaultValue: Wrapped) -> Wrapped {
switch self {
case .none: return defaultValue
case let .some(value): return value
}
}
}
View UIView+ConstraintsSugar.swift
import UIKit
@objc
extension UIView {
func constrain(_ constraints: [NSLayoutConstraint]) {
translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate(constraints)
}
@discardableResult
@samsonjs
samsonjs / MultipartFormEncoder.swift
Created Aug 24, 2017
A multipart form encoder in Swift.
View MultipartFormEncoder.swift
//
// Created by Sami Samhuri on 2017-07-28.
// Copyright © 2017 1 Second Everyday. All rights reserved.
// Released under the terms of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify,
// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following
View references.swift
//: Playground - noun: a place where people can play
import Foundation
final class Disposable {
private let dispose: () -> ()
init(_ dispose: @escaping () -> ()) {
self.dispose = dispose
}
@samsonjs
samsonjs / KeyboardLayoutGuide.swift
Created Jul 19, 2017 — forked from myell0w/KeyboardLayoutGuide.swift
A UILayoutGuide that follows the Keyboard on iOS
View KeyboardLayoutGuide.swift
import Foundation
import UIKit
/// Used to create a layout guide that pins to the top of the keyboard
final class KeyboardLayoutGuide {
private let notificationCenter: NotificationCenter
private let bottomConstraint: NSLayoutConstraint
@samsonjs
samsonjs / LongPressGestureRecognizer.swift
Created Jul 19, 2017 — forked from myell0w/LongPressGestureRecognizer.swift
A UIGestureRecognizer that fires either on long-press or on a force-touch (3D Touch ™️)
View LongPressGestureRecognizer.swift
import Foundation
import UIKit
import UIKit.UIGestureRecognizerSubclass
/// A Gesture Recognizer that fires either on long press, or on "3D Touch"
final class MNTLongPressGestureRecognizer: UILongPressGestureRecognizer {
// MARK: - Properties
@samsonjs
samsonjs / MD5.swift
Created Jul 14, 2017 — forked from pietbrauer/MD5.swift
NSString & NSData to MD5
View MD5.swift
import Foundation
extension NSData {
var md5: NSString {
let digestLength = Int(CC_MD5_DIGEST_LENGTH)
let md5Buffer = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLength)
CC_MD5(bytes, CC_LONG(length), md5Buffer)
let output = NSMutableString(capacity: Int(CC_MD5_DIGEST_LENGTH * 2))
for i in 0..<digestLength {
You can’t perform that action at this time.