Bone warming goodness on a cold rainy day.
- Smoked Salmon (a typical store package seems to work fine)
- Small container heavy cream
- Handful of nice small potatoes (red new, yukon gold, whatev)
- Couple of standard issue carrots
/// The Locale for a currency code. | |
/// | |
/// The returned Locale may only contain currency information. | |
/// | |
/// - Parameter currencyCode: An ISO currency code. See `Locale.commonISOCurrencyCodes` for a list of supported currency codes. | |
/// - Returns: The Locale corresponding to the currency code, or nil if its not a vakid currency code. | |
static func localeFrom(currencyCode: String) -> Locale? { | |
// Make sure the currency code is supported | |
guard self.commonISOCurrencyCodes.contains(currencyCode) else { return nil } |
import UIKit | |
extension UIFont { | |
/// Returns an instance of the font associated with the text style, specified design, and scaled appropriately for the user's selected content size category. | |
/// - Parameters: | |
/// - style: The text style for which to return a font. See UIFont.TextStyle for recognized values. | |
/// - weight: The weight of the font, specified as a font weight constant. For a list of possible values, see "Font Weights” in UIFontDescriptor. Avoid passing an arbitrary floating-point number for weight, because a font might not include a variant for every weight. | |
/// - fontDesign: The new system font design. | |
/// - Returns: A font object of the specified style, weight, and design. |
If you are using the iso8601
strategy, you may not want to rely on the default Equatable
implementation for Date
(==
) when comparing dates. You can use a good old fashion calendar comparison instead.
JSONEncoder and JSONDecoder can both be configured with a strategy (dateEncodingStrategy
and dateDecodingStrategy
) for encoding and decoding dates. There are four named types in addition to allowing you to provide custom options.
| Strategy | Comment |
import Foundation | |
extension String { | |
public func addingPercentEncodingForRFC3986() -> String? { | |
let unreserved = "-._~/?" | |
let allowed = NSMutableCharacterSet.alphanumeric() | |
allowed.addCharacters(in: unreserved) | |
return self.addingPercentEncoding(withAllowedCharacters: allowed as CharacterSet) | |
} | |
import Vapor | |
import LeafErrorMiddleware | |
import APIErrorMiddleware | |
/// Respond with errors based on the requested media type | |
public final class VariantHandlingErrorMiddleware: Middleware, ServiceType { | |
public static func makeService(for container: Container) throws -> Self { | |
return self.init(environment: container.environment) | |
} | |
/// Prints the time taken to execute a closure. | |
/// | |
/// Note: Only for debugging purposes. | |
public func measure<T>(_ label: String = "", _ f: () throws -> (T)) rethrows -> T { | |
let startTime = Date() | |
let result = try f() | |
let endTime = Date().timeIntervalSince(startTime) | |
print("\(label): Time taken", endTime) | |
return result | |
} |