Skip to content

Instantly share code, notes, and snippets.

RAC(self.layer.contents) = [[[[[[RACAble(self.rowView) select:^(YourRowView *rowView) {
return RACAble(rowView, selected);
}] switch] distinctUntilChanged] injectObjectWeakly:self]
doNext:^(RACTuple *x) {
CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"contents"];
fade.duration = 0.15;
[[x.last layer] addAnimation:fade forKey:@"animateContents"];
}] select:^id(RACTuple *x) {
return ([x.first boolValue] ? [self highlightedGradient] : [self standardGradient]);
}];
// Here, rowView is a weak pointer to the view's superview.
RAC(self.layer.contents) = [[[[RACAble(self.rowView.selected) distinctUntilChanged] injectObjectWeakly:self]
doNext:^(RACTuple *x) {
CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"contents"];
fade.duration = 0.15;
[[x.last layer] addAnimation:fade forKey:@"animateContents"];
}] select:^id(RACTuple *x) {
return ([x.first boolValue] ? [self highlightedGradient] : [self standardGradient]);
}];
[[[NSUserDefaultsController sharedUserDefaultsController] rac_subscribableForKeyPath:@"values.yourDefaultsKey" onObject:self] subscribeNext:(id x) {
// do the things
}];
Thread 6 Crashed:: Dispatch queue: com.apple.root.default-priority
0 ??? 0x000000010116a390 0 + 4313228176
1 libdispatch.dylib 0x00007fff9a3634e2 _dispatch_send_wakeup_main_thread + 66
2 libdispatch.dylib 0x00007fff9a364e1c _dispatch_queue_wakeup_main + 48
3 libdispatch.dylib 0x00007fff9a364e91 _dispatch_wakeup + 72
4 libdispatch.dylib 0x00007fff9a364eef _dispatch_queue_push_list_slow + 33
[[[NSUserDefaults standardUserDefaults] rac_subscribableForKeyPath:@"MyUserDefault" onObject:self] subscribeNext:^(id x) {
NSLog(@"%@", x);
}];
@interface MyClass : NSObject
@annotate(APIKey="object_id")
@property (nonatomic, strong) NSString *objectID;
@annotate(APIKey="full_name")
@property (nonatomic, strong) NSString *name;
@end
@joshaber
joshaber / dct_weak.h
Created December 29, 2011 05:22 — forked from rowanj/dct_weak.h
ARC macros for weak references
#ifndef _DCT_WEAK_H
#define _DCT_WEAK_H
// Macros for portable support of notionally weak properties with ARC
// Forked from https://gist.github.com/1354106
// Updated by Rowan James
// Available at https://gist.github.com/1530868
// Defines:
// dct_weak to be used as a replacement for the 'weak' keyword:
// @property (dct_weak) NSObject* propertyName;
NSIndexSet *matches = [self.elements indexesOfObjectsWithOptions:NSEnumerationConcurrent
passingTest:(BOOL ^(ChiroXMLElement *element, NSUInteger index, BOOL *stop){
return (BOOL)([name compare:element.tag options:options] == NSOrderedSame);
})
];
NSString *base64Encode(NSData *data);
NSString *base64Encode(NSData *data) {
BIO *context = BIO_new(BIO_s_mem());
BIO *command = BIO_new(BIO_f_base64());
context = BIO_push(command, context);
BIO_write(context, [data bytes], (int) [data length]);
(void) BIO_flush(context);
char *outputBuffer;
- (NSSize)sizeWithSize:(NSSize)size {
if([self length] < 1) return NSZeroSize;
NSTextContainer *textContainer = [[[NSTextContainer alloc] initWithContainerSize:size] autorelease];
NSTextStorage *textStorage = [[[NSTextStorage alloc] initWithAttributedString:self] autorelease];
NSLayoutManager *layoutManager = [[[NSLayoutManager alloc] init] autorelease];
[layoutManager addTextContainer:textContainer];
[textStorage addLayoutManager:layoutManager];
[layoutManager setHyphenationFactor:0.0];