Skip to content

Instantly share code, notes, and snippets.

func doSomethingClosure(_ completed: ((String) -> Void)) {
completed("We're using closures.")
}
doSomethingClosure { result in
print("result: \(result)")
}
// prints "result: We're using closures."
let disposeBag = DisposeBag()
func doSomethingRx() -> Observable<String> {
return Observable.create { observer in
observer.onNext("We're using RxSwift!")
return Disposables.create()
}
}
@eroth
eroth / gist:7e00fb1455e96ba7dbc3
Last active August 29, 2015 14:03
Pt 2: Obj-C find a parent UIViewController from the child VC (when the child's been pushed from a UINavigationController), then add a custom button to the child that will trigger a method on the parent
// This can all be done from the parent VC--AddSearchRegionsViewController is child
AddSearchRegionsViewController *addSearchRegionsVC = [[AddSearchRegionsViewController alloc] initWithNibName:@"BaseTableView" bundle:[NSBundle mainBundle]];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Test" style:UIBarButtonItemStyleBordered target:self action:@selector(didPressBackButtonOnAddSearchRegionsVC)];
addSearchRegionsVC.navigationItem.backBarButtonItem = backButton;
[self.navigationController pushViewController:addSearchRegionsVC animated:YES];
-(void)didPressBackButtonOnAddSearchRegionsVC {
@eroth
eroth / gist:10614031
Created April 14, 2014 03:35
C++ program I wrote when participating in a recent coding challenge. The object was to read in a text file and follow specified logic.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <fstream>
using namespace std;
struct Legit {
string city;