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
// This sample works on Swift4.2 and Swift5! | |
// Let's try to execute this sample with Playground! | |
import Foundation | |
// - MARK: Artificially RxSwift classes | |
public enum Rx { | |
public final class Observable<E> {} |
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
@testable import 'Your Target Name' | |
import UIKit | |
import Foundation | |
/// Define this protocol in your target | |
// protocol AutoPrivatePropertyAccessible {} | |
// MARK: - PrivatePropertyAccessible | |
protocol PrivatePropertyAccessible { | |
associatedtype PrivatePropertiesCompatible |
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
@testable import 'Your Target Name' | |
import UIKit | |
import Foundation | |
/// Define this protocol in your target | |
// protocol AutoPrivatePropertyAccessible {} | |
// MARK: - PrivatePropertyAccessible | |
protocol PrivatePropertyAccessible { | |
associatedtype PrivatePropertiesCompatible |
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 buildLog = """ | |
""" | |
let regex = try! NSRegularExpression(pattern: "(\\d*.\\d*)ms.*/(.*\\.swift)*", options: []) | |
let range = NSRange(location: 0, length: (buildLog as NSString).length) | |
let results = regex.matches(in: buildLog, options: [], range: range) |
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
// A swift implementation of [this presentetion](https://www.slideshare.net/AkinoriAbe1/aja-2016623). | |
protocol Trait {} | |
enum Z: Trait {} | |
enum S<N: Trait>: Trait {} | |
struct Nat<N: Trait>: CustomStringConvertible { | |
let n: Int | |
fileprivate init(n: Int) { |
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
//: Playground - noun: a place where people can play | |
import Foundation | |
// MARK: - Pub / Sub | |
protocol Subscription { | |
var id: SubscriptionID { get } | |
} |
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
extension NSObject { | |
func remove(observer: NSObject, for keyPath: String) throws { | |
var error: NSError? = nil | |
removeObserver(observer, forKeyPath: keyPath, error: &error) | |
guard let e = error else { return } | |
throw e | |
} | |
} |
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
@implementation NSObject (Error) | |
- (void)removeObserver:(NSObject * _Nonnull)observer forKeyPath:(NSString * _Nonnull)keyPath error:(NSError * _Nullable __autoreleasing * _Nullable)error { | |
@try { | |
[self removeObserver:observer forKeyPath:keyPath]; | |
} @catch (NSException *exception) { | |
NSMutableDictionary *userInfo = nil; | |
if (exception.userInfo == nil) { | |
userInfo = [NSMutableDictionary dictionaryWithCapacity:0]; | |
} else { |
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
extension Array { | |
func unique(predicate: (Element, Element) -> Bool) -> [Element] { | |
var result: [Element] = [] | |
forEach { e -> Void in | |
guard !result.contains({ r -> Bool in | |
return predicate(r, e) | |
}) else { return } | |
result.append(e) | |
} | |
return result |
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
@interface TriangleView() | |
@property (nonatomic, strong, readonly) CAShapeLayer *shapeLayer; | |
@end | |
@implementation TriangleView | |
static NSString *const kAniamtionKey = @"path"; | |
static CGFloat const ANIMATION_DURATION = 0.25f; | |
- (id)initWithFrame:(CGRect)frame { |