Skip to content

Instantly share code, notes, and snippets.

@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 / Other.m
Created June 10, 2013 16:16
Objective-c構文諸々
// 三項演算子例文
NSString *str = (a==b)?@"true":@"false";
@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 / NSPopUpButtonTest.m
Created June 15, 2013 11:00
NSPopUpButton周り
// タイトルを指定してItemを選択
- (void)selectItemWithTitle:(NSString *)title
// インデックスを指定してItemを選択
- (void)selectItemAtIndex:(NSInteger)index
// 選択されているItemのタイトルを取得
- (NSString *)titleOfSelectedItem
@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 / 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 / AppDelegate.m
Created July 4, 2013 15:56
AppDelegate周り
// delegateの取得
AppDelegate *appDelegate = (AppDelegate*)[[NSApplication sharedApplication] delegate];
@katsuhide
katsuhide / FileChooser.m
Created July 5, 2013 16:00
FileChooser
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:YES]; // yes if more than one dir is allowed
NSInteger clicked = [panel runModal];
if (clicked == NSFileHandlingPanelOKButton) {
for (NSURL *url in [panel URLs]) {
// do something with the url here.
NSLog(@"url:%@", [url path]);
}
@katsuhide
katsuhide / NSAlertTest.m
Last active December 19, 2015 10:09
Alert Pop Up
NSString *errorMsg = @"Are you sure you want to delete this Upload Rule?";
if(errorMsg.length != 0){
NSAlert *alert = [ NSAlert alertWithMessageText: @"hoge"
defaultButton: @"OK" // 1
alternateButton: @"Cancel" // 0
otherButton: nil // -1
informativeTextWithFormat: @"%@", errorMsg];
NSLog(@"%ld",[alert runModal]);
@katsuhide
katsuhide / Webkit.m
Created July 17, 2013 16:39
WebKit周り
// Webページを開く
- (IBAction)loadWebPage:(id)sender
{
NSLog(@"load web page");
NSString *urlAddress = [_urlField stringValue];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[_webView mainFrame] loadRequest:requestObj];