This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
public extension UIDevice { | |
var modelName: String { | |
var systemInfo = utsname() | |
uname(&systemInfo) | |
let machineMirror = Mirror(reflecting: systemInfo.machine) | |
let identifier = machineMirror.children.reduce("") { identifier, element in | |
guard let value = element.value as? Int8, value != 0 else { return identifier } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIFont { | |
static func printFonts() { | |
UIFont.familyNames.forEach({ familyName in | |
let fontNames = UIFont.fontNames(forFamilyName: familyName) | |
print(familyName, fontNames) | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSMutableAttributedString { | |
@discardableResult func bold(_ text: String) -> NSMutableAttributedString { | |
let attrs: [NSAttributedStringKey: Any] = [.font: UIFont(name: "NotoSans-Bold", size: 14)!] | |
let boldString = NSMutableAttributedString(string:text, attributes: attrs) | |
append(boldString) | |
return self | |
} | |
@discardableResult func normal(_ text: String) -> NSMutableAttributedString { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSTextAttachment { | |
func setImageHeight(height: CGFloat) { | |
guard let image = image else { return } | |
let ratio = image.size.width / image.size.height | |
bounds = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: ratio * height, height: height) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension NSError { | |
public class var emptyErrorDomain: String { return "com.ap.error.default" } | |
public class var emptyErrorCode: Int { return 1024 } | |
public class var empty: NSError { | |
return NSError(domain: emptyErrorDomain, code: emptyErrorCode, userInfo: nil) | |
} | |
public class func make(message: String, code: Int = 9999) -> NSError { | |
return NSError( | |
domain: "com.ap.error.maker", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIView { | |
func fadeIn(_ duration: Double) { | |
fadeIn(duration, 0) | |
} | |
func fadeOut(_ duration: Double) { | |
fadeOut(duration, 0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
public extension UIApplication { | |
var statusBarView: UIView? { | |
return value(forKey: "statusBar") as? UIView | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIView { | |
@IBInspectable var cornerRadius: CGFloat { | |
get { | |
return layer.cornerRadius | |
} | |
set { | |
layer.cornerRadius = newValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class FirstLaunchHelper { | |
let wasLaunchedBefore: Bool | |
var isFirstLaunch: Bool { | |
return !wasLaunchedBefore | |
} | |
init(getWasLaunchedBefore: () -> Bool, | |
setWasLaunchedBefore: (Bool) -> ()) { | |
let wasLaunchedBefore = getWasLaunchedBefore() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// MARK: Encode/decode helpers | |
class JSONNull: Codable { | |
public init() {} | |
public required init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
if !container.decodeNil() { |
OlderNewer