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
#import <Foundation/Foundation.h> | |
@interface TestClass : NSObject | |
@property (nonatomic, strong) __attribute__((NSObject)) CFStringRef str; | |
@end | |
@implementation TestClass | |
@end | |
int main(int argc, char* argv[]) { |
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
/* When adding the persistent store to a PSC | |
pragmaOptions = [[NSDictionary alloc] initWithObjectsAndKeys:@"WAL", @"journal_mode", nil]; | |
storeOptions = [[NSDictionary alloc] initWithObjectsAndKeys:pragmaOptions, NSSQLitePragmasOption, nil]; | |
This will allow multiple readers, and at most writer to connect to the Sqlite DB. Default journalling only allows multiple readers OR 1 writer (ie. writing blocks all reading). | |
*/ |
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
static NSString *MYObservationContext = @"MYObservationContext"; | |
[object addObserver:self forKeyPath:@"key.path" options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:(void*)&MYObservationContext]; | |
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | |
if (context == &MYObservationContext) { | |
id oldValue = [change objectForKey:NSKeyValueChangeOldKey]; | |
id newValue = [change objectForKey:NSKeyValueChangeNewKey]; | |
// Do something | |
} |
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
// When the dom node is [object HTMLObjectElement] | |
// element is not a valid object ==> crash | |
- (void)mouseMoved:(NSEvent *)theEvent { | |
NSPoint mouseLocation = [self.webView convertPoint:[theEvent locationInWindow] fromView:nil]; | |
mouseLocation.y = [self.webView frame].size.height - mouseLocation.y; | |
id element2 = [[self.webView windowScriptObject] evaluateWebScript:[NSString stringWithFormat:@"document.elementFromPoint(%f,%f);", mouseLocation.x, mouseLocation.y]]; | |
id element = [[self.webView windowScriptObject] evaluateWebScript:[NSString stringWithFormat:@"\"result: \" + document.elementFromPoint(%f,%f)", mouseLocation.x, mouseLocation.y]]; |
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
__block NSManagedObject* object = nil; | |
[privateQueueContext performBlockAndWait:^{ | |
object = [SomeClass methodThatExecutesFetchRequestReturningObjectUsingContext:privateQueueContext]; | |
}]; | |
// Is it safe to use object here? | |
NSLog(@"object: %@", object); |
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
NSArray* stringArray = [NSArray arrayWithObjects:@"One", @"Two", @"Three", @"Four", nil]; | |
[stringArray enumerateObjectsUsingBlock:^(NSString* obj, NSUInteger idx, BOOL *stop) { | |
NSLog(@"%@", obj); | |
}]; |
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
UIImage* newImage = [UIImage imageNamed:context]; | |
// set up an animation for the transition the content | |
CATransition *animation = [CATransition animation]; | |
[animation setDuration:0.25]; | |
[animation setType:kCATransitionPush]; | |
[animation setSubtype:kCATransitionFromRight]; | |
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; | |
[[self.contentImageView layer] addAnimation:animation forKey:@"SwitchToView1"]; |
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
CGSize imageSize = CGSizeMake(1000, 1000); | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); | |
CGContextRef theContext = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, 4*imageSize.width, colorSpace, kCGImageAlphaPremultipliedLast); | |
[layerView.layer renderInContext:theContext]; | |
// Layer tree has backgroundFilters set on some of the CALayers | |
// When it's rendered in the Bitmap Context, none of these filters are applied. |
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
- (void)webViewDidFinishLoad:(UIWebView *)webView | |
{ | |
if (webView.subviews.count > 0) | |
{ | |
id aView = [webView.subviews objectAtIndex:0]; | |
if ([aView respondsToSelector:@selector(setScrollEnabled:)]) | |
{ | |
((UIScrollView*)aView).scrollEnabled = NO; | |
} |
NewerOlder