Skip to content

Instantly share code, notes, and snippets.

Avatar

Samuel Mellert samuel-mellert

View GitHub Profile
@samuel-mellert
samuel-mellert / NSObject+KVO.h
Last active May 30, 2017
Safely remove KVO-observer.
View NSObject+KVO.h
@interface NSObject (KVO)
- (void)safelyRemoveObserver:(nonnull NSObject *)observer forKeyPath:(nonnull NSString *)keyPath;
@end
@samuel-mellert
samuel-mellert / UIFont+MonospacedDigitsFont.swift
Last active Sep 20, 2016
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.
View UIFont+MonospacedDigitsFont.swift
//
// 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
Extension to UIFont that allows to use UIFont.systemFontOfSize:weight: on iOS >= 7
View UIFont+SizeAndWeight.swift
//
// 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 Jan 13, 2016
Creates a random alphanumeric string with a defined length.
View RandomString.swift
// 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]
}
View UIFont+MonospacedDigits
extension UIFont {
static func monospacedDigitsSystemFontOfSize(fontSize: CGFloat, weight: CGFloat) -> UIFont {
let originalFontDescriptor = UIFont.systemFontOfSize(fontSize, weight: weight).fontDescriptor()
let fontDescriptorFeatureSettings = [
[
UIFontFeatureTypeIdentifierKey: kNumberSpacingType,
UIFontFeatureSelectorIdentifierKey: kMonospacedNumbersSelector