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
| NSNumber *intNum = @1; | |
| NSNumber *floatNum = @1.23f; | |
| NSNumber *doubleNum = @1.2345; | |
| NSNumber *boolNum = @YES; | |
| NSNumber *charNum = @'a'; | |
| int numInt = [intNum intValue]; | |
| float numFloat = [floatNum floatValue]; | |
| double numDouble = [doubleNum doubleValue]; | |
| BOOL numBool = [boolNum boolValue]; |
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
| //ローカルな定数 | |
| static NSString * const kFirstName = @"hachinobu"; | |
| //グローバルな定数 | |
| //ヘッダーファイル内で宣言 | |
| extern NSString * const FirstName; | |
| //実装ファイルで定義 | |
| NSString *const FirstName = @"hachinobu"; |
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
| UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(40, 50, 180, 180)]; | |
| view1.backgroundColor = [UIColor redColor]; | |
| [self.view addSubview:view1]; | |
| UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(70, 90, 180, 200)]; | |
| view2.backgroundColor = [UIColor yellowColor]; | |
| [self.view addSubview:view2]; | |
| CGRect unionRect = CGRectUnion(view1.frame, view2.frame); | |
| NSLog(@"unionRect:%@", NSStringFromCGRect(unionRect)); | |
| UIView *unionView = [[UIView alloc] initWithFrame:unionRect]; | |
| unionView.backgroundColor = [UIColor clearColor]; |
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
| - (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]; | |
| } | |
| } |
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
| //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; |
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* html = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].outerHTML"]; | |
| //bodyタグ内 | |
| NSString* html = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"]; |
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
| //ステータスバー領域を含む画面の領域 | |
| CGRect bounds = [UIScreen mainScreen].bounds; | |
| ステータスバー領域を含まない画面の領域 | |
| CGRect applicationFrame = [UIScreen mainScreen].applicationFrame; |
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
| + (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]; |
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
| ja.lprojとen.lprojフォルダを作成してそれぞれの言語ファイルを同じ名前で入れる。 | |
| en.lprojフォルダ配下は自動で認識されるがja.lprojフォルダ配下は[Target Membership]にチェックが外れているのでチェックを入れればローカライズされる。 |
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
| //集計対象 | |
| 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]; |
OlderNewer