Re: Message dialog on Cocoa
Re: Message dialog on Cocoa
- Subject: Re: Message dialog on Cocoa
- From: Alastair Houghton <email@hidden>
- Date: Fri, 20 Jul 2007 11:35:55 +0100
On 20 Jul 2007, at 10:48, Felipe Monteiro de Carvalho wrote:
On 7/20/07, ∞ <email@hidden> wrote:
creating a NSString to pass to NSRunAlertPanel
You can create a NSString literal easily in .m files by using
@"This is a
NSString literal". You can also use CFStringRef's by casting them to
(NSString*) thanks to Apple's toll-free bridging (which makes many
CFxxx
types exactly the same as Cocoa NSxxx types).
Nice!
But are they really identical or some operation is performed on the
type-cast?
Yes and no. The point is that they (usually) behave identically,
though toll-free-bridged types are not necessarily identical in their
implementations. AFAIK it's even possible to pass your own
subclasses of NString as CFStringRefs (for instance).
String literals, I think, are the same in both cases, because their
layout is controlled by the compiler rather than by the runtime.
Most NSStrings that you see in your code are actually NSCFStrings
(which means they're really CFStrings underneath, I believe).
Also, remember that you need to check before assuming something is
toll-free bridged. Most of the basic classes/CF types are, but some
(e.g. NSRunLoop) have very similarly named Core Foundation
equivalents (e.g. CFRunLoop), but are *not* toll-free bridged.
I tryed to create some CFStringRef's and give them to NSRunAlertPanel,
but I receive many error messages:
2007-07-20 11:41:27.568 cocoamsg[433] *** _NSAutoreleaseNoPool():
Object 0x306bc0 of class NSCFString autoreleased with no pool in place
- just leaking
Not to mention that the dialog doesn't show.
You're calling this from another thread, right? And you haven't
created an autorelease pool (you must do this explicitly if you
expect to use Cocoa from your new thread). And you're trying to use
GUI functionality from a thread other than your main thread (so check
that the functionality in question is documented as working from
another thread... many things do not, and I expect that
NSRunAlertPanel() is one of them).
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden