Skip to content

Instantly share code, notes, and snippets.

@hachinobu
hachinobu / gist:5ca2eba859dfc8da3d86
Last active August 29, 2015 14:02
パフォーマンス測定とボトルネック箇所の特定

InstrumentsのTime Profilerを使用する。

Call Treeのチェックマークは

Invert Call Tree

Hide Missing Symbol

Hide System Libraries

@hachinobu
hachinobu / gist:ec2b9f4a32fbb6b696af
Created June 12, 2014 10:02
iPhone用のxibファイルをiPad用のxibファイルに変更する
iPhone用のxibファイルを選択して[File] - [Duplicate]を選択して名前の最後に~iPadをつける。
~iPad.xibを右クリックして[Open As] - [Source Code]で開く
type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" を
type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" に置換。
targetRuntime="iOS.CocoaTouch" を
targetRuntime="iOS.CocoaTouch.iPad" に置換。
// immutableなString型の配列
let names: String[] = ["name5", "name2", "name1", "name3"]
//各データを取得
let name1 = names[0] //name5
let name2 = names[1] //name2
let name3 = names[2] //name1
let name4 = names[3] //name3
//各件数
@hachinobu
hachinobu / gist:998b8ae26065b8e069c2
Created May 9, 2014 10:30
CoreDataでcount関数を使う
//集計対象
NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"column1"];
//集計関数countを指定
NSExpression *countExpression = [NSExpression expressionForFunction:@"count:" arguments:@[keyPathExpression]];
//集計式の対象(NSExpressionDescription )
NSExpressionDescription *expressionDescription = [[[NSExpressionDescription alloc] init] autorelease];
[expressionDescription setName:@"count"];
[expressionDescription setExpression:countExpression];
[expressionDescription setExpressionResultType:NSInteger32AttributeType];
@hachinobu
hachinobu / gist:9802771
Created March 27, 2014 08:16
複数ファイルの一気にローカライズする方法
ja.lprojとen.lprojフォルダを作成してそれぞれの言語ファイルを同じ名前で入れる。
en.lprojフォルダ配下は自動で認識されるがja.lprojフォルダ配下は[Target Membership]にチェックが外れているのでチェックを入れればローカライズされる。
@hachinobu
hachinobu / UIColorHex
Created March 27, 2014 06:47
16進数カラーコードからUIColorを作成する
+ (UIColor *)colorWithHexString:(NSString *)hex
{
//先頭に#がついていた場合は#を削除
if ([hex hasPrefix:@"#"]) {
hex = [hex substringFromIndex:1];
}
unsigned int rgb[3];
for (int i = 0; i < 3; i++) {
NSString *component = [hex substringWithRange:NSMakeRange(i * 2, 2)];
NSScanner *scanner = [NSScanner scannerWithString:component];
@hachinobu
hachinobu / mainScreen
Created March 26, 2014 08:55
ステータスバー領域を含む画面の領域とステータスバー領域を含まない画面の領域の取得方法
//ステータスバー領域を含む画面の領域
CGRect bounds = [UIScreen mainScreen].bounds;
ステータスバー領域を含まない画面の領域
CGRect applicationFrame = [UIScreen mainScreen].applicationFrame;
@hachinobu
hachinobu / gist:9594135
Last active August 29, 2015 13:57
UIWebViewで表示しているHTMLのソースコード取得
//全文
NSString* html = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].outerHTML"];
//bodyタグ内
NSString* html = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];
@hachinobu
hachinobu / UIImageResize
Created March 13, 2014 08:15
UIImageのリサイズ方法
//UIImageのリサイズ
- (UIImage *)resizeImage:(UIImage *)image rect:(CGRect)rect
{
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);
[image drawInRect:rect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
UIGraphicsEndImageContext();
return resizedImage;
@hachinobu
hachinobu / gist:9361841
Created March 5, 2014 05:38
CoreDataよりNSFetchRequestをsetReturnsDistinctResults:YES、setResultType:NSDictionaryResultTypeで取得した際に返り値であるNSDictionaryをNSManagedObjectに変換する方法
- (id)initWithDictionary:(NSDictionary *)dict managedContext:(NSManagedObjectContext *)context
{
self = [super initWithEntity:[NSEntityDescription entityForName:[[self class] entityName] inManagedObjectContext:context] insertIntoManagedObjectContext:nil];
if (self) {
for (NSString *key in dict.allKeys) {
[self setValue:dict[key] forKey:key];
}
}