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
| @implementation PSPDFTableViewCell // UITableViewCell subclass | |
| /** | |
| On iOS 10, constraints involving a UITableViewCell’s contentView’s layoutMarginsGuide are removed for some | |
| reason before the cell appears, which breaks the layout. This layout guide is a working alternative. | |
| */ | |
| - (UILayoutGuide *)pspdf_layoutMarginsGuide { | |
| if (@available(iOS 11.0, *)) { | |
| return self.contentView.layoutMarginsGuide; | |
| } |
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
| // Douglas Hill, October 2018 | |
| import UIKit | |
| /** | |
| A scroll view that honours the reduce motion accessibility setting. | |
| If reduce motion is enabled, animated adjustments to contentOffset | |
| will use a cross dissolve instead of translation. |
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
| private extension UIContentSizeCategory { | |
| var shortDescription: String { | |
| switch self { | |
| case .unspecified: return "unspecified" | |
| case .extraSmall: return "XS" | |
| case .small: return "S" | |
| case .medium: return "M" | |
| case .large: return "L" | |
| case .extraLarge: return "XL" |
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
| // Douglas Hill, February 2018 | |
| import Foundation | |
| /// Returns a localised string with the key as an enum case so the compiler checks it exists. | |
| /// The enum should be automatically generated using UpdateLocalisedStringKeys.swift. | |
| public func localisedString(_ key: LocalisedStringKey) -> String { | |
| return Bundle.main.localizedString(forKey: key.rawValue, value: nil, table: nil) | |
| } |
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; | |
| @import CoreGraphics; | |
| @import ImageIO; | |
| static NSUInteger maxThumbnailSize = 20; | |
| extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); | |
| /// Returns a CGImage with a +1 retain count. | |
| static CGImageRef createThumbnailFromURL(NSURL *imageURL, NSUInteger maxPixelSize) |
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 | |
| let dictionary = ["one": 1, "two": 2] | |
| let lazyValues = dictionary.values | |
| let jsonData = try JSONSerialization.data(withJSONObject: lazyValues, options: []) | |
| // ❗️ Argument type 'LazyMapCollection<Dictionary<String, Int>, Int>' does not conform to expected type 'AnyObject' |
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
| @implementation NSArray (DHRandom) | |
| - (nullable id)dh_random { | |
| if (self.count == 0) { | |
| return nil; | |
| } | |
| return self[arc4random_uniform((u_int32_t)self.count)]; | |
| } | |
| @end |
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; | |
| NS_ASSUME_NONNULL_BEGIN | |
| @interface DHLazyLinkedList<ObjectType> : NSArray<ObjectType> | |
| - (instancetype)initWithRootObject:(ObjectType)rootObject nextObjectBlock:(ObjectType _Nullable (^)(ObjectType))next NS_DESIGNATED_INITIALIZER; | |
| - (nullable ObjectType)objectAfterObject:(ObjectType)object; |
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
| #include <CoreGraphics/CoreGraphics.h> | |
| static inline CGFloat gammaCorrect(CGFloat component) { | |
| if (component > 0.04045f) { | |
| return pow((component + 0.055f) / 1.055f, 2.4f); | |
| } | |
| return component / 12.92f; | |
| } |