This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 recursive(observable: Observable<Int>) -> Observable<Int> { | |
| return observable.flatMap { value -> Observable<Int> in | |
| guard value < 10 else { | |
| return Variable(-1).asObservable() | |
| } | |
| print(value) | |
| return recursive(Variable(value + 1).asObservable()) | |
| } | |
| } |
This file contains hidden or 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
| protocol TestResourceType: JRResourceType { | |
| typealias ServiceType = TestService | |
| } | |
| struct TestService: JRServiceType { |