Re: How can I convince an NSBigMutableString to become a mere NSAttributedString ?
Re: How can I convince an NSBigMutableString to become a mere NSAttributedString ?
- Subject: Re: How can I convince an NSBigMutableString to become a mere NSAttributedString ?
- From: Charles Srstka <email@hidden>
- Date: Tue, 17 Jul 2012 19:50:58 -0500
On Jul 17, 2012, at 6:58 PM, Erik Stainsby wrote:
> I'm working with the text from a multiline NSTextField. When it arrives in the delegate it is represented in an NSBigMutableString. Casting this to a NSAttributedString seems to have no effect on the actual class being used by the NSString cluster.
>
> I can't seem to find any documentation on NSBigMutableString.
>
> Can someone with deep experience tell me if I can _safely_ assume that NSBMS will respect all of NSAttributedString's method calls ?
>
> Also if I have a convenience function in a category, should I rewrite it as a category on NSString ? Or directly on the NSBMS, which seems to be a hidden class? Writing a category on a hidden class just doesn't feel right.
NSBigMutableString is a private subclass of NSString. NSAttributedString is *not* a subclass of NSString; however, you can easily make an NSAttributedString from an NSString (which is what you have). Something like this:
- (BOOL)control:(NSControl *)control isValidObject:(id)object {
NSAttributedString *aStr = nil;
if ([object isKindOfClass:[NSAttributedString class]]) {
aStr = [object copy]; // or mutableCopy, or just use the given instance, etc.
} else if ([object isKindOfClass:[NSString class]]) {
aStr = [[NSAttributedString alloc] initWithString:object];
}
// do whatever with your attributed string
}
and you should be good. You don’t care whether the class is NSBigMutableString or some other hidden subclass; all you care about is that it’s some kind of NSString (or NSAttributedString).
Charles
_______________________________________________
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