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
a = "foo bar baz" | |
puts a | |
puts a.scan(/f+/) | |
puts "========" | |
b = "foo 10 bar 20 baz 30" | |
puts b | |
puts b.scan(/\w+/) | |
puts "========" |
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
@interface NSDate (Util) | |
- (NSDate*)toLocalTime; | |
@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
// 現在時間を取得 | |
NSDate *now = [NSDate date]; | |
NSLog(@"now:%@", [now toLocalTime]); // now:2013-06-01 00:19:46 +0000 | |
// 現在時間にインターバル時間を足す | |
NSTimeInterval interval = 3600; // 秒 | |
NSDate *after = [now dateByAddingTimeInterval:interval]; | |
NSLog(@"after:%@", [after toLocalTime]); // after:2013-06-01 01:19:46 +0000 | |
// 時間の判定 |
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
/* | |
* main | |
*/ | |
- (void)run{ | |
// タイマーで使うデータ | |
NSNumber *number = [[NSNumber alloc] initWithInt:1]; | |
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:number forKey:@"count"]; | |
// タイマーを作成 | |
NSTimer *timer = [NSTimer |
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
// DB設定情報 | |
NSString *databaseName = @"main.db"; | |
NSString *path = @"/tmp"; | |
NSString *databasePath = [path stringByAppendingPathComponent:databaseName]; | |
FMDatabase *db = [FMDatabase databaseWithPath:databasePath]; | |
// Query | |
NSString *sql = @"select hoge1, hoge2 participants from hoge;"; | |
// Open DB |
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
// 3秒スリープ | |
[NSThread sleepForTimeInterval:3]; | |
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
// 空のNSMutableStringを生成 | |
NSMutableString *mstr = [NSMutableString string]; | |
// 文字列を指定した生成 | |
NSString *str = @"hoge" | |
if(str != nil){ | |
NSMutableString *mstr = [NSMutableString stringWithString:str]; | |
} | |
// 文字列を追加 |
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
// autorelease onで生成 | |
NSMutableArray *Array = [NSMutableArray array]; | |
// autorelease offで生成 | |
NSMutableArray *Array = [[NSMutableArray alloc] init]; | |
NSMutableArray *Array = [[NSMutableArray alloc] initWithObjects: nil]; | |
// 配列の作成 | |
NSArray *ar = [NSArray arrayWithObjects:@"東京", @"名古屋", @"大阪", 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
/* | |
* save | |
*/ | |
-(void)save{ | |
NSError *error = nil; | |
if (![[self managedObjectContext] commitEditing]) { | |
NSLog(@"%@:%@ unable to commit editing before saving", [self class], NSStringFromSelector(_cmd)); | |
} | |
if (![[self managedObjectContext] save:&error]) { | |
[[NSApplication sharedApplication] presentError:error]; |
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
// short型→NSNumber型 | |
NSNumber *num = [NSNumber numberWithShort:32767]; | |
// int型→NSNumber型 | |
NSNumber *num = [NSNumber numberWithInt:2147483647]; | |
// long型→NSNumber型 | |
NSNumber *num = [NSNumber numberWithLong:2147483647]; | |
// float型→NSNumber型 |
OlderNewer