Cocoa分類文章 顯示方式:簡文 | 列表

August 1,2005

Cocoa & SQLite


最近因為某計畫準備開始動作,目前正在做預備研讀
資料庫的部分正在考慮XML或是SQLite挑一個

XML之前印像中有看到相關的Cocoa物件,於是先找 SQLite 的部分

嗯,當然先拜請咕狗大神 Google:// [Cocoa] [SQLite]


After 30 sec



addPersistentStoreWithType:configuration:URL:options:error:

The store type is a string constant such as NSSQLiteStoreType.
啥? NSSQLiteStoreType? 那還有支援啥米?



After another 30 sec



Persistent Store Type

Description

Availability

NSSQLiteStoreType

A SQLite database.

Mac OS X v10.4 and later.

NSXMLStoreType

An XML file.

Mac OS X v10.4 and later.

NSBinaryStoreType

A binary file.

Mac OS X v10.4 and later.

NSInMemoryStoreType

An in-memory store.

Mac OS X v10.4 and later.


全……全包了是吧(汗),真是好樣的 Cocoa,這樣會讓人越來越懶啊ORZ

Posted by toki_kanno at 樂多Roodo!17:45回應(0)引用(0)

June 25,2005

Resize NSImage

NSImage *resizedImage = [[NSImage alloc] initWithSize: theNewSize];

// lock focus on resized image
[resizedImage lockFocus];

[NSGraphicsContext saveGraphicsState];

// set image interpolation -> high (better resize quality)
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];

// src draw to resized
[image drawInRect:NSMakeRect(0.0,0.0,theNewSize.width, theNewSize.height)
fromRect:NSMakeRect(0.0,0.0,[image size].width, [image size].height)
operation:NSCompositeCopy fraction:1.0];

[NSGraphicsContext restoreGraphicsState];

[resizedImage unlockFocus];

Posted by toki_kanno at 樂多Roodo!12:06回應(0)引用(0)

從 NSImage 獲得 NSBitmapImageRep


  1. Lock focus on source NSImage.

  2. Use - (id)initWithFocusedViewRect:(NSRect)rect of NSBitmapImageRep


Posted by toki_kanno at 樂多Roodo!11:57回應(0)引用(0)

Fundation Tool

[little tip]
寫 command line mode 程式的時候,Project 類別時選用 Funcdation Tool
就可以在 coomand line mode 下使用 Cocoa 裡各種方便的物件

Posted by toki_kanno at 樂多Roodo!11:23回應(0)引用(0)

May 16,2005

在Cocoa下將字串由中文轉到 UTF8

UInt32 big5 = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingBig5_HKSCS_1999);

NSString* test = [NSString stringWithCString:"中文測試" encoding:big5];
NSLog("%@", [test UTF8String]);

Posted by toki_kanno at 樂多Roodo!21:04回應(0)引用(0)

April 11,2005

Cocoa - NSLog 應用

NSLog主要用以顯示除錯訊息,其用法和一般printf相同
但NSLog會在訊息前加入程式名稱及時間碼

另外,由於Cocoa中大部分的函式都是吃NSString
也因此,NSLog的用法會變成如下(要在字串的雙引號前加上@符號)

EX:
NSLog(@"Object description = %@", testobj);

其中%@ 的格式字串(format string)代表印出物件描述(object description)
而物件描述又可以透過覆載(override)該物件的description method來更改

最後,若寫的是GUI程式,則預設NSLog的訊息是不會顯示的,要用Debug模式去跑
才會有除錯訊息出現。

Posted by toki_kanno at 樂多Roodo!1:41回應(0)引用(0)

April 7,2005

Cocoa 下直接存取圖檔 pixel 的方式

unsigned char* byte;


//註: 下面(1)(2)兩行可以合成一行
// NSBitmapImageRep* tmpbmp = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
... blah blah blah];


NSBitmapImageRep* tmpbmp = [NSBitmapImageRep alloc]; //(1)
[tmpbmp initWithBitmapDataPlanes: nil //(2)
pixelsWide: 24
pixelsHigh: 24
bitsPerSample: 1
samplesPerPixel: 1
hasAlpha: NO
isPlanar: YES
colorSpaceName: NSCalibratedWhiteColorSpace
bytesPerRow: 3
bitsPerPixel: 1];

byte = [tmpbmp bitmapData]; // 這個指標指向圖形的像素資料

Posted by toki_kanno at 樂多Roodo!17:16回應(0)引用(1)

Cocoa 下的 Message Dialog

Cocoa 下的 Message Dialog 請用

NSRunAlertPanel(@"視窗標題", @"顯示訊息", @"預設按鈕文字,通常是OK", nil, nil);

後面兩個不常用的設成 nil 或 NULL 即可

Posted by toki_kanno at 樂多Roodo!17:10回應(0)引用(1)
 [1]