<% flash.each do |type, message| %> | |
<div class="alert <%= bootstrap_class_for(type) %> fade in"> | |
<button class="close" data-dismiss="alert">×</button> | |
<%= message %> | |
</div> | |
<% end %> |
#import <objc/runtime.h> | |
static void SwizzleClassMethod(Class klass, SEL original, SEL new) | |
{ | |
Method origMethod = class_getClassMethod(klass, original); | |
Method newMethod = class_getClassMethod(klass, new); | |
if (class_addMethod(klass, original, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) { | |
class_replaceMethod(klass, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); |
# nil? can be used on any Ruby object. It returns true only if the object is nil. | |
nil.nil? # => true | |
[].nil? # => false | |
{}.nil? # => false | |
"".nil? # => false | |
" ".nil? # => false | |
true.nil? # => false | |
# empty? can be used on some Ruby objects including Arrays, Hashes and Strings. It returns true only if the object's length is zero. | |
nil.empty? # NoMethodError: undefined method `empty?' for nil:NilClass |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
#!/usr/bin/env ruby | |
device_types_output = `xcrun simctl list devicetypes` | |
device_types = device_types_output.scan /(.*) \((.*)\)/ | |
runtimes_output = `xcrun simctl list runtimes` | |
runtimes = runtimes_output.scan /(.*) \(.*\) \((com.apple[^)]+)\)$/ | |
devices_output = `xcrun simctl list devices` | |
devices = devices_output.scan /\s\s\s\s(.*) \(([^)]+)\) (.*)/ |
/* This SnapshotHelper class should be compatible with SnapshotHelper.swift version 1.2 */ | |
@import Foundation; | |
@import XCTest; | |
@interface SnapshotHelper : NSObject | |
- (instancetype)initWithApp:(XCUIApplication*)app; | |
- (void)snapshot:(NSString*)name waitForLoadingIndicator:(BOOL)wait; |
func fetchUserId() -> Observable<String> { | |
return create{ (observer) -> Disposable in | |
Client.fetchUserId() { [unowned self] | |
(userId: String?, err: ErrorType?) -> Void in | |
if let _ = err{ | |
observer.on(Event.Error(err!)) | |
} else { | |
observer.on(Event.Next(userId)) | |
observer.on(Event.Completed) | |
} |
import Foundation | |
internal final class MulticastDelegate<T> { | |
private var delegates = [Weak]() | |
func add(_ delegate: T) { | |
if Mirror(reflecting: delegate).subjectType is AnyClass { | |
let weakValue = Weak(value: delegate as AnyObject) | |
guard delegates.index(of: weakValue) == nil else { | |
return |
- 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.