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
public extension Collection { | |
func anySatisfy(_ predicate: (Self.Element) throws -> Bool) rethrows -> Bool { | |
try reduce(false) { | |
try predicate($1) || $0 | |
} | |
} | |
} |
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
// Created by Marcin Krzyzanowski | |
import Foundation | |
public protocol JSONEncodable: Encodable { } | |
public extension JSONEncodable { | |
func toJSON(using encoder: @autoclosure () -> JSONEncoder = JSONEncoder()) throws -> String { | |
try String(decoding: encoder().encode(self), as: UTF8.self) | |
} |
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
// Marcin Krzyzanowski | |
// blog.krzyzanowskim.com | |
import Foundation | |
extension URLResourceKey { | |
static let bookmarkAllPropertiesKey = URLResourceKey("NSURLBookmarkAllPropertiesKey") | |
static let fileIDKey = URLResourceKey("_NSURLFileIDKey") | |
static let inode = URLResourceKey.fileIDKey | |
} |
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
class Foo { | |
struct Flags: OptionSet { | |
let rawValue: Int | |
static let one = Flags(rawValue: 1 << 0) | |
static let two = Flags(rawValue: 1 << 1) | |
static let three = Flags(rawValue: 1 << 2) | |
} | |
private(set) var _flags: Flags = [.one, .two] |
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
@propertyWrapper | |
struct Wrap<T> { | |
var wrappedValue: T? | |
} | |
class Foo { | |
@Wrap() | |
var name: String | |
} |
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
// | |
// MultilineLabel.swift | |
// | |
// Created by Marcin Krzyzanowski on 19/09/2019. | |
// | |
import UIKit | |
public class MultilineLabel: UILabel { | |
override public init(frame: CGRect) { |
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
// instead doing this | |
let dict: Dictionary<String, Any> = [:] | |
dict["name"] = "Marcin" | |
// do this if it's closed set | |
enum Keys: String, CaseIterable { | |
case name, address | |
} | |
// or this if it's open set |
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
$ clang -x c++ -E -dM -o - /dev/null | |
#define OBJC_NEW_PROPERTIES 1 | |
#define _LP64 1 | |
#define __APPLE_CC__ 6000 | |
#define __APPLE__ 1 | |
#define __ATOMIC_ACQUIRE 2 | |
#define __ATOMIC_ACQ_REL 4 | |
#define __ATOMIC_CONSUME 1 | |
#define __ATOMIC_RELAXED 0 | |
#define __ATOMIC_RELEASE 3 |
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
// https://twitter.com/krzyzanowskim/status/1149607371204784129 | |
extension TimeInterval { | |
static func minutes(_ minutes: Int) -> TimeInterval { | |
return TimeInterval(seconds(60) * TimeInterval(minutes)) | |
} | |
static func seconds(_ seconds: Int) -> TimeInterval { | |
return TimeInterval(seconds) | |
} |
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
// https://twitter.com/krzyzanowskim/status/1142800558480351232 | |
// Private "NSCTFontUIUsageAttribute" overwrites public "NSFontFamilyAttribute" attribute 🙃😌 if both set. | |
extension UIFontDescriptor.AttributeName { | |
static let fontUIUsageAttribute = UIFontDescriptor.AttributeName.init(rawValue: "NSCTFontUIUsageAttribute") | |
} | |
extension UIFontDescriptor { | |
class func preferredFontDescriptor(withTextStyle style: UIFont.TextStyle, family: String) -> UIFontDescriptor { | |
let preferredFontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style).withFamily(family) |