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.

@lludo
lludo / managedObjectModel
Created November 7, 2014 08:08
Initialize a managed object model with swift that will work for Tests and Application
lazy var managedObjectModel: NSManagedObjectModel = {
// The managed object model for the application.
let modelURL = NSBundle.mainBundle().URLForResource("<appName>", withExtension: "momd")!
let managedObjectModel = NSManagedObjectModel(contentsOfURL: modelURL)!
// Check is we are running as test or not
let environment = NSProcessInfo.processInfo().environment as [String : AnyObject]
let isTest = (environment["XCInjectBundle"] as? String)?.pathExtension == "xctest"
@lludo
lludo / String+Regex
Created November 6, 2014 21:37
String extension that returns a new string with matches of a regex replaced by a transformation
extension String {
func replace(regularExpression: NSRegularExpression, transform: (String) -> String) -> String {
var output = ""
var lastMatchedLocation = self.startIndex
let rangeAll = NSMakeRange(0, countElements(self));
regularExpression.enumerateMatchesInString(self, options: NSMatchingOptions(0), range: rangeAll) {
@mbinna
mbinna / RunUnitTests.sh
Last active October 25, 2017 12:59
Run Xcode Application Tests from the command line
#!/bin/sh
# Launch application using ios-sim and set up environment to inject test bundle into application
# Source: http://stackoverflow.com/a/12682617/504494
if [ "$RUN_APPLICATION_TESTS_WITH_IOS_SIM" = "YES" ]; then
test_bundle_path="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.$WRAPPER_EXTENSION"
environment_args="--setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection --setenv XCInjectBundle=$test_bundle_path --setenv XCInjectBundleInto=$TEST_HOST"
ios-sim launch $(dirname $TEST_HOST) $environment_args --args -SenTest All $test_bundle_path
echo "Finished running tests with ios-sim"