Re: Objective-C Question
Re: Objective-C Question
- Subject: Re: Objective-C Question
- From: Dave <email@hidden>
- Date: Tue, 12 Mar 2013 15:41:07 +0000
On 12 Mar 2013, at 13:37, Graham Cox wrote:
On 12/03/2013, at 11:45 PM, Dave <email@hidden> wrote:
Except it doesn't do what the above does!
Yes it does.
Oh No it doesn't!
<crowd echo's Oh Yes it does!>
It creates a copy of read only dictionary and then modifies that. If
the underlying dictionary changes, you will not see the changes
reflected in the copy!
@implementation DF2
+ (NSDictionary*) dictionary
{
NSMutableDictionary* md = [[super dictionary] mutableCopy];
// add extra items to md
return [md autorelease];
}
From reading the above, I cant see this is any better than what I
have, it fact it copies the dictionary every time, which is not
what is wanted as well as being slower.
Is it? Have you measured it? Does it matter?
Well, like anyone else I'd like it run run as fast as possible and
anyway, it is of course slower, it would have to send a retain
message to each Object in the dictionary.
In any case, it was only an example of how to achieve what you
want, to show how to use class inheritance.
To be honest, the rest of your explanation doesn't make any sense
to me, and I can't really be bothered to unravel it. Your whole "I
can't instantiate the class" is incoherent at best (you *are*
instantiating the class, like it or not).
Ok, instantiate the object that is defined by the class!, to spell it
out do a [[theClass alloc] init];,
I'm not sure what you mean by
(you *are* instantiating the class, like it or not)
The class may well be being instantiated, but AFAIK, there is no
statement in the App that does this, apart from the @interface
definition if that''s what you mean,
Maybe it makes sense to you, but not to me. I was trying to cut
across all that irrelevant discussion by going back to basics and
trying to get you to understand that:
It makes sense to a whole lot more people that me and something very
similar is done in an Apple Sample somewhere too.
a) [super class] is a meaningless construct, in that it doesn't do
anything different from [self class],
I know that now, but it's not instantly obvious to me anyway! It's a
language gotcha, I will remember now hopefully.
b) in a class method, [self class] is just self,
c) a class method is just an ordinary instance method of the class
object.
If you can understand those points, the rest should follow
naturally. What you are trying to do is very straightforward, and
requires no special trickery.
There why not just look at the original post and say, ahhhhh you need
to change it to use [super xxxx], instead of all the other stuff that
didn't even do the same thing!
The attempts you made show a clear lack of understanding about
inheritance, which is what others were trying to tell you.
Not it doesn't! It shows that I was confused after 16 hours coding by
the difference between [[super class] xxxx] and [super xxxx]. From
reading my original and subsequent posts, only a complete moron or
someone trying to cause upset would say "The attempts you made show a
clear lack of understanding about inheritance". If you are serious
and not just trying to wind me up and you are a complete moron, then
please do explain how you can say that after looking at the original
post.
Take the following example:
@interface BaseClass
+(NSMutableDictionary*) newDict;
@end
@implementation BaseClass
+(NSMutableDictionary*) newDict
{
return [[NSMutableDictionary alloc] init];
}
@class NewClass;
@interface NewClass : BaseClass
+(NSMutableDictionary*) newDict;
@end
#import "BaseClass.h"
@implementation NewClass
+(NSMutableDictionary*) newDict
{
NSMutableDictionary* myDict;
myDict = [[super class] newDict]; //***********************
should be [super NewDict];
[myDict setObject:@"Some Data" forKey:@"someKey"];
return [[NSMutableDictionary alloc] init];
}
@end
So, what is it? Wind up merchant or Moron?
All the Best
Dave
_______________________________________________
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