Skip to content

Instantly share code, notes, and snippets.

View samuel-mellert's full-sized avatar
🏠
Working from home

Samuel Mellert samuel-mellert

🏠
Working from home
View GitHub Profile
@samuel-mellert
samuel-mellert / NSObject+KVO.h
Last active May 30, 2017 15:07
Safely remove KVO-observer.
@interface NSObject (KVO)
- (void)safelyRemoveObserver:(nonnull NSObject *)observer forKeyPath:(nonnull NSString *)keyPath;
@end
@samuel-mellert
samuel-mellert / UIFont+MonospacedDigitsFont.swift
Last active September 20, 2016 09:18
Extension to UIFont that allows to create a monospaced digits font from a instance of UIFont. If the font is not a San Francisco font it simply returns self.
//
// UIFont+MonospacedDigitsFont.swift
//
// Created by Samuel Mellert on 29/12/15.
//
import UIKit
extension UIFont {
@samuel-mellert
samuel-mellert / UIFont+SizeAndWeight.swift
Last active May 21, 2019 02:20
Extension to UIFont that allows to use UIFont.systemFontOfSize:weight: on iOS >= 7
//
// UIFont+SizeAndWeight.swift
//
// Created by Samuel Mellert on 08/01/16.
//
import UIKit
public enum FontWeight {
case Normal
@samuel-mellert
samuel-mellert / RandomString.swift
Created January 13, 2016 09:26
Creates a random alphanumeric string with a defined length.
// Swift 2 code
func randomString(length: Int) -> String {
let charactersString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
let charactersArray = Array(arrayLiteral: charactersString)
var string = ""
for _ in 0..<length {
string += charactersArray[Int(arc4random()) % charactersArray.count]
}
extension UIFont {
static func monospacedDigitsSystemFontOfSize(fontSize: CGFloat, weight: CGFloat) -> UIFont {
let originalFontDescriptor = UIFont.systemFontOfSize(fontSize, weight: weight).fontDescriptor()
let fontDescriptorFeatureSettings = [
[
UIFontFeatureTypeIdentifierKey: kNumberSpacingType,
UIFontFeatureSelectorIdentifierKey: kMonospacedNumbersSelector