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
| // NSArray+NSDictionary.m | |
| #import "NSObject+NSDictionary.h" | |
| @implementation NSArray (NSDictionary) | |
| - (NSDictionary*)toDictionary | |
| { | |
| NSMutableDictionary *dict = [NSMutableDictionary new]; | |
| [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { |
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
| - (void)dealloc | |
| { | |
| [NSObject cancelPreviousPerformRequestsWithTarget:self]; | |
| [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
| if ([self respondsToSelector:@selector(setDelegate:)]) | |
| [self performSelector:@selector(setDelegate:) withObject:nil]; | |
| [super dealloc]; // not needed in ARC | |
| } |
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
| // Fix the crash in iOS6 when you start a not supported video stream | |
| // note: do not use initWithUrl, instead use setContentURL | |
| MPMoviePlayerViewController viewController = [[MPMoviePlayerViewController alloc] init]; | |
| viewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming; | |
| viewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen; | |
| [viewController.moviePlayer setContentURL:url]; |
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
| @implementation NSDictionary (Values) | |
| - (id)valueForKeyPath:(NSString *)keyPath | |
| { | |
| __block id value = nil; | |
| if (keyPath != nil) { | |
| NSArray *keys = [keyPath componentsSeparatedByString:@"."]; | |
| if (keys && [keys count] > 0) { | |
| [keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { |
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
| NSString *input = @"\\u5404\\u500b\\u90fd"; | |
| CFStringTransform((__bridge CFMutableStringRef)input, NULL, CFSTR("Any-Hex/Java"), YES); | |
| NSLog(@"Readable string: %@", input); |
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
| # put script in ~/Library/Application Support/TextWrangler/Text Filters/Format JSON.py | |
| #!/usr/bin/python | |
| import fileinput | |
| import json | |
| if __name__ == "__main__": | |
| text = '' | |
| for line in fileinput.input(): | |
| text = text + ' ' + line.strip() | |
| jsonObj = json.loads(text) | |
| print json.dumps(jsonObj, sort_keys=True, indent=2) |
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
| # put script in ~/Library/Application Support/TextWrangler/Text Filters/Tidy XML.py | |
| #!/bin/sh | |
| XMLLINT_INDENT=$'\t' xmllint --format --encode utf-8 - |
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
| // UILabel text size fit macro | |
| // | |
| // use : | |
| // | |
| // UILabel *label = .... | |
| // TEXT_FIT(label, @"your text here"); | |
| // | |
| #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) | |
| #define TEXT_FIT_IOS6(t,txt) (CGRect){t.frame.origin, t.frame.size.width, [txt sizeWithFont:t.font constrainedToSize:t.frame.size lineBreakMode:t.lineBreakMode].height} | |
| #define TEXT_FIT_IOS7(t,txt) (CGRect){t.frame.origin, t.frame.size.width, [txt boundingRectWithSize:t.frame.size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:t.font} context:nil].size.height} |
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
| NSString *input = @"\\u5404\\u500b\\u90fd"; | |
| CFStringTransform((__bridge CFMutableStringRef)input, NULL, CFSTR("Any-Hex/Java"), YES); | |
| NSLog(@"Readable string: %@", input); |
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
| // | |
| // ReviewEngine.h | |
| // | |
| // Created by Danilo Priore on 23/11/11. | |
| // Copyright (c) 2011 Prioregroup.com. All rights reserved. | |
| // | |
| // ReviewEngine simplifies the calling to app internet page for requesting a | |
| // user review of the app on the app store. To use it simply drop the two | |
| // files into your code and then add one method call to get it working. |