This file contains hidden or 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 UIImage { | |
public convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height:1)) { | |
let rect = CGRect(origin: .zero, size: size) | |
UIGraphicsBeginImageContextWithOptions(rect.size, false, 1.0) | |
color.setFill() | |
UIRectFill(rect) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
guard let cgImage = image?.cgImage else { |
This file contains hidden or 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 NSObject { | |
private struct AssociatedKeys { | |
static var extensionProps: UInt8 = 0 | |
} | |
private var extensionProps: NSObject? { | |
get { | |
return objc_getAssociatedObject(self, &AssociatedKeys.extensionProps) as? NSObject | |
} | |
set { | |
objc_setAssociatedObject(self, &AssociatedKeys.extensionProps, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) |
This file contains hidden or 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
// | |
// UIColor+hex.swift | |
// | |
// Created by Hisoka0917 on 2018/1/24. | |
// Copyright © 2018. All rights reserved. | |
// | |
import UIKit | |
import Foundation |
This file contains hidden or 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 | |
// Copy from https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24 | |
struct JSONCodingKeys: CodingKey { | |
var stringValue: String | |
init?(stringValue: String) { | |
self.stringValue = stringValue | |
} |
This file contains hidden or 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
/** | |
``` | |
// Encode a model with properties of type [String : Any] | |
var propertiesContainer = container.nestedContainer(keyedBy: DynamicKey.self, forKey: .properties) | |
if let properties = properties { | |
try propertiesContainer.encodeDynamicKeyValues(withDictionary: properties) | |
} | |
``` | |
inspired by https://gist.github.com/samwize/a82f29a1fb34091cd61fc06934568f82 | |
*/ |
This file contains hidden or 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 { | |
public var top: CGFloat { | |
get { | |
return self.frame.origin.y | |
} | |
set { | |
var frame = self.frame | |
frame.origin.y = newValue |
NewerOlder