Skip to content

Instantly share code, notes, and snippets.

@katsuhide
katsuhide / UITest.m
Created June 29, 2013 14:26
UI周り
// Comboboxを初期化
[_directoryField selectItemAtIndex:0];
// Comboboxの選択されているindexを取得
[_directoryField indexOfSelectedItem]
// NSWidowを半透明に(0.0 ~ 1.0)
[_window setAlphaValue:1.0];
// 背景を設定
@katsuhide
katsuhide / FileManagerTest.m
Created June 16, 2013 07:11
FileManager(ファイル操作)周り
// ファイルマネージャを作成
NSFileManager *fileManager = [NSFileManager defaultManager];
// ファイルが存在するか?
if ([fileManager fileExistsAtPath:filePath]) { // yes
NSLog(@"%@は既に存在しています", filePath);
} else {
NSLog(@"%@は存在していません", filePath);
}
@katsuhide
katsuhide / NSPopUpButtonTest.m
Created June 15, 2013 11:00
NSPopUpButton周り
// タイトルを指定してItemを選択
- (void)selectItemWithTitle:(NSString *)title
// インデックスを指定してItemを選択
- (void)selectItemAtIndex:(NSInteger)index
// 選択されているItemのタイトルを取得
- (NSString *)titleOfSelectedItem
@katsuhide
katsuhide / SQLite.sql
Created June 11, 2013 16:20
SQLite Query
-- dual table
select 1;
-- JST現在時刻を出力
select strftime('%Y-%m-%d %H:%M:%S', datetime('now', 'localtime')) as strftime;
-- UTC時刻
select datetime('now');
select datetime('now', 'utc');
@katsuhide
katsuhide / Other.m
Created June 10, 2013 16:16
Objective-c構文諸々
// 三項演算子例文
NSString *str = (a==b)?@"true":@"false";
@katsuhide
katsuhide / NSDictionary.m
Created June 10, 2013 00:18
NSDictionary周り
// 空の可変ディクショナリ生成例
NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
// 値とキー値を指定した生成例
NSDictionary *dic = [NSDictionary dictionaryWithObject:@"hoge" forKey:@"Key"];
// 値とキー値を複数指定する生成例
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
@"hoge", @"name",
@"999-9999-9999", @"tel",
@katsuhide
katsuhide / NSNumberTest.m
Created June 9, 2013 07:23
NSNumber周り
// short型→NSNumber型
NSNumber *num = [NSNumber numberWithShort:32767];
// int型→NSNumber型
NSNumber *num = [NSNumber numberWithInt:2147483647];
// long型→NSNumber型
NSNumber *num = [NSNumber numberWithLong:2147483647];
// float型→NSNumber型
@katsuhide
katsuhide / CoreDataTest.m
Last active December 18, 2015 00:38
CoreData周り
/*
* 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];
@katsuhide
katsuhide / NSArrayTest.m
Last active December 18, 2015 00:29
配列(NSArray, NSMutableArray)周り
// autorelease onで生成
NSMutableArray *Array = [NSMutableArray array];
// autorelease offで生成
NSMutableArray *Array = [[NSMutableArray alloc] init];
NSMutableArray *Array = [[NSMutableArray alloc] initWithObjects: nil];
// 配列の作成
NSArray *ar = [NSArray arrayWithObjects:@"東京", @"名古屋", @"大阪", nil];
@katsuhide
katsuhide / NSStringTest.m
Last active December 17, 2015 23:59
文字列周り
// 空のNSMutableStringを生成
NSMutableString *mstr = [NSMutableString string];
// 文字列を指定した生成
NSString *str = @"hoge"
if(str != nil){
NSMutableString *mstr = [NSMutableString stringWithString:str];
}
// 文字列を追加