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
for familyName in UIFont.familyNames() { | |
println("Font family name: \(familyName)") | |
println("Font names under family: \(UIFont.fontNamesForFamilyName(familyName as String))") | |
} |
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 | |
/// Mocks network responses. Useful to be used with Unit/UI tests. | |
class ResponseMocker { | |
/// Returns a mocked `JSON` object encapsulated in an `AnyObject`, | |
/// representing a mocked endpoint response. | |
/// | |
/// - returns: A mocked `JSON` object encapsulated in an `AnyObject`, | |
/// representing a Notice root endpoint response. |
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 | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "YYYY-MM-dd'T'HH:mm:ssZZZZZ" | |
let date = dateFormatter.date(from: "2018-03-02T10:00:00-0800") | |
Calendar.current.isDateInToday(date!) |
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 | |
/// Clamps the given `value` into the range defined by `minValue` and `maxValue`. For example: | |
/// | |
/// (0.0 ... 5.0).clamp(4.2) = 4.2 | |
/// (0.0 ... 5.0).clamp(-1.3) = 0.0 | |
/// (0.0 ... 5.0).clamp(6.4) = 5.0 | |
/// | |
/// Source: https://stackoverflow.com/a/46799935/584548 |
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
// Fix for error: "Expected to decode Double but found a string/data instead" | |
public struct CodableEntity: Codable { | |
public let myBool: Bool | |
public let myDate: Date | |
public let myInt: Int | |
} | |
let jsonData = Data(""" |
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 | |
import PlaygroundSupport | |
extension UILabel { | |
/// Makes the first line (of a multiline label) bold. | |
/// In case the label is a "single line" one, the function does nothing. | |
/// In case there is no bold version of the current font, the function does nothing. | |
public func makeFirstLineBold() { |
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 | |
import PlaygroundSupport | |
let subviewFrame = CGRect(x: 50, y: 50, width: 300, height: 300) | |
let subview = UIView(frame: subviewFrame) | |
subview.backgroundColor = .yellow | |
subview.layer.cornerRadius = 20 | |
subview.layer.shadowColor = UIColor.black.cgColor |
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
#!/usr/bin/swift | |
import Foundation | |
let jsonData = Data(""" | |
{ | |
"premiumBundle": { | |
"enabled": true, | |
"variations": { | |
"sku1": { |
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
// `POST` receiving an `Request` and returning an `ReceiptValidation`. | |
func validate(_ request: Request) throws -> Future<ReceiptValidation> { | |
let promise = request.eventLoop.newPromise(ReceiptValidation.self) | |
DispatchQueue.global().async { | |
guard let receipt = try? request.content.decode(Receipt.self).wait() else { | |
promise.fail(error: Abort(HTTPResponseStatus.badRequest)) | |
return | |
} |
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
[ | |
{ | |
"keys": ["super+enter"], | |
"command": "build" | |
}, | |
{ | |
"keys": ["super+shift+c"], | |
"command": "show_u200b" | |
}, | |
{ |
OlderNewer