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
// An example of a model object with a boolean property | |
// that's backed by an NSNumber from a JSON response | |
@interface ModelObject : NSObject | |
@property (nonatomic, assign, getter = isEnabled) BOOL enabled; | |
@end | |
@interface ModelObject () |
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
# In the debugger: | |
# (fill in <home> and <image> below with your user path and the image's ivar | |
p (BOOL)[(NSFileManager *)[NSFileManager defaultManager] createFileAtPath:@"<home>/Desktop/image.png" contents:(void *)UIImagePNGRepresentation(<image>) attributes: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
// | |
// UIApplication+NetworkActivity.h | |
// | |
// Created by Christopher Bowns on 4/11/12. | |
// Original implementation: http://stackoverflow.com/a/6978817/774 | |
// Copyright (c) 2012 Mechanical Pants Software | |
// | |
#import <UIKit/UIKit.h> |
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
- (CGPoint)center:(CGPoint)oldCenter movedFromAnchorPoint:(CGPoint)oldAnchorPoint toAnchorPoint:(CGPoint)newAnchorPoint withFrame:(CGRect)frame; | |
{ | |
CGPoint anchorPointDiff = CGPointMake(newAnchorPoint.x - oldAnchorPoint.x, newAnchorPoint.y - oldAnchorPoint.y); | |
CGPoint newCenter = CGPointMake(oldCenter.x + (anchorPointDiff.x * frame.size.width), | |
oldCenter.y + (anchorPointDiff.y * frame.size.height)); | |
return newCenter; | |
} |
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
/* | |
System Versioning Preprocessor Macros via http://stackoverflow.com/questions/3339722/check-iphone-ios-version | |
Example: | |
if (UIDeviceSystemVersionLessThan(@"4.0")) { | |
// code for pre-4.0 devices. | |
} | |
if (UIDeviceSystemVersionGreaterThanOrEqualTo(@"3.1.1")) { | |
// Code for 3.1.1. |
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
// | |
// IPInsetLabel.h | |
// Instapaper | |
// | |
// Created by Marco Arment on 7/23/11. | |
// Copyright 2011 Instapaper LLC, released to the public domain. | |
// | |
#import <UIKit/UIKit.h> |
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
// JSON is dangerous, take one of these! | |
+ (id)nullGuardedDict:(NSDictionary *)dict valueForKey:(NSString *)key; | |
{ | |
id obj = nil; | |
obj = [dict valueForKey:key]; | |
if (obj == [NSNull null]) { | |
obj = nil; | |
} | |
return 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
#!/usr/bin/ruby | |
#Just run this script in a terminal window, leaving the window open in the | |
#background so it can continue to process messages. | |
IO.popen("syslog -F \'$(Sender): $Message\' -w -k Sender com.apple.backupd") { |syslogIO| | |
while (inputString = syslogIO.gets) do | |
escapedString = inputString.gsub("'", "\\'") | |
`/usr/local/bin/growlnotify -a 'Time Machine' -t 'Time Machine' -m '#{escapedString}'` | |
end | |
} |
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+MPImageNamedNilCheck.h | |
// | |
// Created by Christopher Bowns on 5/6/12. | |
// Copyright (c) 2012 Mechanical Pants Software. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIImage (MPImageNamedNilCheck) |
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
// Please don’t do this. | |
// Need to change UISearchBar’s cancel button text? | |
// Well, there’s no API for that. | |
// (Sorry UIKit.) | |
UISearchBar *searchBar = [self.searchDisplayController searchBar]; | |
for (UIView *view in [searchBar subviews]) { … <left as an exercise to the adventurous> } |