Author: Chris Lattner
- Proposal: SE-XXXX
- Authors: Chris Lattner, Joe Groff
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.
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
'use strict'; | |
var React = require('react-native'); | |
var { | |
Bundler, | |
StyleSheet, | |
Text, | |
TouchableHighlight, | |
View, | |
ScrollView, |
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
#if DEBUG | |
#import <MediaPlayer/MediaPlayer.h> | |
#endif | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
#if DEBUG | |
// Debug code that lets us simulate memory warnings by pressing the device's volume buttons. |
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
# before this file is loaded, a locale should be set: | |
# | |
# In a browser environment, you can use: | |
# ```<script>__locale='en';</script>``` | |
# | |
# In a server environment (specifically node.js): | |
# ```global.__locale = 'en';``` | |
# normalize in-app locale string to "en" or "de-AT" | |
parts = @__locale.split('-') |
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
var s:Sprite = new Sprite(); | |
var mc:MovieClip = new MovieClip(); | |
var b:Button = new Button(); | |
var arr:Array = [ s, mc, b, this ]; | |
for each( var obj:Object in arr ) | |
{ | |
switch( obj.constructor ) | |
{ |
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
Function.prototype.or = function(callback) { | |
var next = this; | |
return function(err, doc) { | |
if (err) { | |
callback(err, doc); | |
} else { | |
next(doc, callback); | |
} | |
}; | |
}; |
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
package asx.string | |
{ | |
public class ColorizeTest | |
{ | |
var colors:Object = { red: red, green: green, yellow: yellow, blue: blue, purple: purple, cyan: cyan, gray: gray }; | |
[Test] | |
public function colorize_shouldReturnColorizedString():void | |
{ | |
for (var color:String in colors) |
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
//Throw this on your UITableViewDelegate (probably your UITableViewController) to achieve the "keyboard dismisses when I tap away" effect. | |
//Your users will thank you. A lot. | |
- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView { | |
[self.view endEditing:YES]; | |
} | |
//The endEditing: method on UIView comes to us from a category that UITextField adds to UIKit that makes the view or any subview that is the first responder resign (optionally force), that's what the "YES" bit is. |
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
function lineTowards(g:Graphics, x:int, y:int, length:int):void | |
{ | |
var c:Number = Math.sqrt(Math.sqr(x) + Math.sqr(y)); | |
var ratio:Number = length / c; | |
g.lineTo(x*ratio, y*ratio); | |
} |
NewerOlder