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
class TouchGoThroughView: UIView { | |
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { | |
super.point(inside: point, with: event) && pointInsideVisibleSubviews(point, with: event) | |
} | |
} | |
extension UIView { | |
func pointInsideVisibleSubviews(_ point: CGPoint, with event: UIEvent?) -> Bool { |
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 | |
struct SortDescriptor<Value> { | |
let compare: (Value, Value) -> ComparisonResult | |
} | |
extension Collection { | |
func sorted(by sortDescriptors: [SortDescriptor<Element>]) -> [Element] { | |
sorted { a, b in |
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 String { | |
func draw(fontSize: CGFloat) -> UIImage? { | |
draw(font: .systemFont(ofSize: fontSize)) | |
} | |
func draw(font: UIFont) -> UIImage? { | |
draw(attributes: [.font: font], backgroundColor: .clear) | |
} | |
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 KeyedDecodingContainer { | |
func decode<T: NSCoding>(_ type: T.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> T? { | |
let data = try decode(Data.self, forKey: key) | |
return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? T ?? nil | |
} | |
} | |
extension KeyedEncodingContainer { |
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
@objcMembers | |
private class BlockHandler: NSObject { | |
var block: (() -> Void)? | |
@objc func runBlock() { | |
block?() | |
} | |
} |
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 | |
class FullContentIntrinsicSizeTableView: UITableView { | |
override var contentSize: CGSize { | |
didSet { | |
if contentSize != oldValue { | |
invalidateIntrinsicContentSize() | |
} | |
} |
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 UIAlertController { | |
func setLeftAlignedMessage(_ message: String) { | |
let paragraphStyle = NSMutableParagraphStyle() | |
paragraphStyle.alignment = .left | |
let messageText = NSMutableAttributedString( | |
string: message, |
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 UITableView { | |
func dequeueReusableCell(withIdentifier identifier: String, registerNibIfNeededWithNibName nibName: String) -> UITableViewCell? { | |
guard let cell = dequeueReusableCell(withIdentifier: identifier) else { | |
register(UINib(nibName: nibName, bundle: nil), forCellReuseIdentifier: identifier) | |
return dequeueReusableCell(withIdentifier: 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
func delay(_ delay: Double, closure: @escaping () -> Void) { | |
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: closure) | |
} |
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 | |
import UIKit | |
class SimpleCollectionViewDataSource<Cell: AnyObject, Object>: NSObject, UICollectionViewDataSource { | |
var objects: [[Object]] | |
func objectAtIndexPath(indexPath: NSIndexPath) -> Object { | |
return objects[indexPath.section][indexPath.row] | |
} |
NewerOlder