Re: AppKit Addition usage
Re: AppKit Addition usage
- Subject: Re: AppKit Addition usage
- From: Andrew Merenbach <email@hidden>
- Date: Thu, 23 Aug 2007 14:19:35 -0700
Hi, James,
To quote an article on the Cocoa-Dev web site (not to be confused
with the mailing list):
Note: AppKit is not thread-safe, so this code might do harm to your
computer, make you unpopular and/or make your wife/husband
pregnant. Use at your own risk (and I'd not recommend to). Look at
distributed objects if you want to...
You can't use the -size method from any thread but the main one.
Perhaps try something like this:
- (void)myNewThreadMethod {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSAttributedString *string = [[NSAttributedString alloc]
initWithString:@"hello!"];
[self performSelectorOnMainThread:@selector
(measureSizeOfAttributedString:) withObject:string waitUntilDone:YES];
[string release];
// now, you can do something with the accessor
NSSize theSize = [self attributedstringSize];
[pool release];
}
- (void)measureSizeOfAttributedString:(NSAttributedString *)aString {
[self setAttributedStringSize:[aString size]];
}
- (NSSize)attributedStringSize {
@synchronized(self) {
return attributedStringSize;
}
return NSZeroSize;
}
- (void)setAttributedStringSize:(NSSize)aSize {
@synchronized(self) {
attributedStringSize = aSize;
}
}
On Aug 23, 2007, at 2:03 PM, James Trankelson wrote:
Hi,
I've transferred over some code that uses NSAttributedString AppKit
extensions, and it crashes in my new environment with a BAD_ACCESS.
I'm trying to call the size method of the NSAttributedString
extension. Is there something I've forgotten to do to make this work?
Shouldn't I just be able to include the AppKit framework and have it
work ok?
These calls don't need to be in any particular thread or anything,
right?
Thanks
-jt
_______________________________________________
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
_______________________________________________
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