Skip to content

Instantly share code, notes, and snippets.

View plantpurecode's full-sized avatar
🎯

Jacob Relkin plantpurecode

🎯
View GitHub Profile
prefix operator ..
infix operator ..: MultiplicationPrecedence
/*
Custom operator that lets you configure an instance inline
```swift
let label = UILabel()..{
$0.numberOfLines = 0
$0.textColor = .systemRed
}
@propertyWrapper
public struct AnyProxy<EnclosingSelf, Value> {
private let keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>
public init(_ keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>) {
self.keyPath = keyPath
}
@available(*, unavailable, message: "The wrapped value must be accessed from the enclosing instance property.")
public var wrappedValue: Value {
//
// Created by Eric Firestone on 3/22/16.
// Copyright © 2016 Square, Inc. All rights reserved.
// Released under the Apache v2 License.
//
// Adapted from https://gist.github.com/blakemerryman/76312e1cbf8aec248167
import Foundation
xcrun llvm-cov report -use-color=true -instr-profile \
./Build/Intermediates/CodeCoverage/Coverage.profdata \
./Build/Intermediates/CodeCoverage/MyApp/Products/Debug-iphonesimulator/MyApp.app/MyApp
anonymous
anonymous / NSStringVariations.m
Created February 18, 2015 08:32
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
void (^benchmark)(const char *str) = ^(const char *str) {
const long count = 10000000;
NSDate *start = [NSDate date];
for (long i = 0; i < count; i++) {
(void)[[NSString alloc] initWithUTF8String:str];
}
@jspahrsummers
jspahrsummers / GHRunLoopWatchdog.h
Created January 28, 2015 20:50
A class for logging excessive blocking on the main thread
/// Observes a run loop to detect any stalling or blocking that occurs.
///
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
@ayanonagon
ayanonagon / Locale.playground
Created October 19, 2014 20:31
Changing the locale in a Swift playground
import UIKit
extension NSLocale {
class func currentLocale() -> NSLocale {
return NSLocale.localeWithLocaleIdentifier("en_GB");
}
}
NSLocale.currentLocale().localeIdentifier
// See: https://devforums.apple.com/message/1000934#1000934
import Foundation
// Logic
operator prefix ¬ {}
@prefix func ¬ (value: Bool) -> Bool {
return !value
}
@staltz
staltz / introrx.md
Last active November 14, 2024 11:27
The introduction to Reactive Programming you've been missing