Skip to content

Instantly share code, notes, and snippets.

@lattner
lattner / async_swift_proposal.md
Last active April 21, 2024 09:43 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@bdash
bdash / generics.m
Last active March 13, 2018 22:06
Using Objective-C generics with type constraints on forward-declared classes?
#import <Foundation/Foundation.h>
@interface Base : NSObject
@end
@interface GenericCollection<T: Base *> : NSObject
@end
@class Derived2;
@subfuzion
subfuzion / curl.md
Last active May 3, 2024 09:26
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@gkoehler
gkoehler / ViewController.swift
Created November 12, 2015 13:23
UICollectionView: performBatchUpdates example
//
// ViewController.swift
// collView2
//
// Created by Gavin Koehler on 11/11/15.
// Copyright © 2015 From Now On, LLC. All rights reserved.
//
import UIKit
@xareelee
xareelee / NSObject+PropertyName.h
Last active May 2, 2019 13:43
Objective-C property name to a string with autocompletion and compile-time check
// Release under MIT
// Copyright (C) 2015 Xaree Lee
#import <Foundation/Foundation.h>
/* Get property name for the class (C string or NSSting). */
#define keypathForClass(Klass, PropertyName) \
(((void)(NO && ((void)[Klass _nullObjectForCheckingPropertyName].PropertyName, NO)), # PropertyName))
#define keypathStringForClass(Klass, PropertyName) \
@keypathForClass(Klass, PropertyName)
@sindresorhus
sindresorhus / compile-objc.sh
Last active November 25, 2023 21:13
Compile Objective-C on the command-line with clang
# -fobjc-arc: enables ARC
# -fmodules: enables modules so you can import with `@import AppKit;`
# -mmacosx-version-min=10.6: support older OS X versions, this might increase the binary size
clang main.m -fobjc-arc -fmodules -mmacosx-version-min=10.6 -o main
@n-b
n-b / fp-obj-c.m
Created February 9, 2015 09:28
fp-obj-c
//#!/usr/bin/env objc-run
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
///
/// Typedefs
typedef id (^TargetMethod)(id arg);
@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
@arturlector
arturlector / ios-questions-interview.md
Last active February 25, 2024 18:44
Вопросы на собеседование iOS разработчика.

Вопросы на собеседование iOS разработчика (дополненное издание):

General:

  • Что такое полиморфизм?

  • Что такое *инкапсуляция? Что такое *нарушение инкапсуляции?

  • Чем абстрактный класс отличается от интерфейса?

  • Расскажите о паттерне MVC. Чем отличается пассивная модель от активной?

@quinntaylor
quinntaylor / CompilerCheckedKeyPaths.h
Created November 13, 2014 06:14
Code for getting compiler check on key paths, more accurate than using NSStringFromSelector(@selector(foo)).
// See http://nshipster.com/key-value-observing/
// Put this code a common utilities header, and use it to have the compiler help check correctness of key paths.
// Uses macro stringification to create an Obj-C string literal, plus validation code that the compiler optimizes out.
@interface NSObject (KeyPathFakeCategoryForCompilerWarnings)
+ (instancetype)__fake_method_for_compiler_warnings__;
- (instancetype)__fake_method_for_compiler_warnings__;
@end
/*! Returns a string for the given keypath, but causes a compiler warning if the keypath is not defined on \c self.