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
NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ | |
[[[RACSignal startEagerlyWithScheduler:[RACScheduler scheduler] block:^(id <RACSubscriber> subscriber) { | |
NSManagedObjectContext *context = [NSManagedObjectContext contextWithMainContext:self.managedObjectContext]; // self is AppDelegate | |
[context attachToCurrentScheduler]; | |
[subscriber sendNext:nil]; | |
[subscriber sendCompleted]; | |
}] saveContext] subscribeCompleted:^{ | |
NSLog(@"Completed"); | |
}]; | |
}]; |
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 Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
let first : Int? = "1".toInt() | |
let second : Int? = "2".toInt() | |
switch (first, second) { | |
case (.Some(let f), .Some(let s)): | |
println(f + s) | |
default: | |
println("error") | |
} |
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
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 50.0, 500.0)]; | |
view.translatesAutoresizingMaskIntoConstraints = NO; | |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 50.0, 44.0)]; | |
label.translatesAutoresizingMaskIntoConstraints = NO; | |
label.lineBreakMode = NSLineBreakByWordWrapping; | |
[label setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; | |
[label setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; | |
label.text = @"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | |
label.numberOfLines = 0; | |
NSLog(@"%@", NSStringFromCGRect(label.frame)); |
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
let person = NSEntityDescription.insertNewObjectForEntityForName("Person", inManagedObjectContext: context) as Person |
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
class A { | |
var firstName: String? | |
var lastName: String? | |
} | |
class B: A { | |
var middleName: String? | |
} |
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
let a: Int? = 10 | |
let b: Int? = 20 | |
let values = [a, b].flatMap { $0 } | |
let c: Int? = values.isEmpty ? nil : values.reduce(0, combine: +) |
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
func get<T>(sv: T, key: String) -> Any? { | |
let mirror = Mirror(reflecting: sv) | |
for (name, value) in mirror.children where name == key { | |
return value | |
} | |
return nil | |
} |
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
UISearchBar *searchBar = [[[UISearchBar alloc] initWithFrame:CGRectZero] autorelease]; | |
[searchBar sizeToFit]; | |
self.tableView.tableHeaderView = searchBar; | |
[[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease]; | |
self.searchDisplayController.delegate = self; | |
self.searchDisplayController.searchResultsDataSource = self; | |
self.searchDisplayController.searchResultsDelegate = self; |
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 NS_BLOCKS_AVAILABLE | |
- (void)showWhileExecutingBlock:(void (^)())block animated:(BOOL)animated { | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { | |
block(); | |
dispatch_async(dispatch_get_main_queue(), ^(void) { | |
[self cleanUp]; | |
}); | |
}); | |
OlderNewer