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 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 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 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 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 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 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 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) |
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 XCTAssertThrowsError2<T>(_ expression: () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line, _ errorHandler: (Error) -> Void = { _ in }) { | |
do { | |
_ = try expression() | |
XCTFail(message()) | |
} catch { | |
errorHandler(error) | |
} | |
} |
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 A {} | |
// foo | |
func foo<T>(_ v: T, handler: () -> Void) -> T { | |
print("regular") | |
return v | |
} | |
func foo<T>(_ v: T?, handler: () throws -> Void) rethrows -> T? { |
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
// https://bugs.swift.org/browse/SR-10906 | |
import Foundation | |
protocol ViewDataSource: class { | |
func foo<T>() -> [T] | |
} | |
class View { | |
weak var delegate: ViewDataSource? |