[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Segfault in -[NSObject dealloc]
From: |
Stefan Urbanek |
Subject: |
Re: Segfault in -[NSObject dealloc] |
Date: |
Fri, 19 May 2006 08:25:25 +0200 |
User-agent: |
Internet Messaging Program (IMP) 3.2.2 |
Citát Michael Gardner <address@hidden>:
> Ah, I thought I couldn't use the usual alloc method since I'm obtaining the
> Class dynamically. I didn't even realize you could do something like the
> following:
>
> [objc_getClass("Foo") alloc]
>
Simple rule. Do this:
NSString *myClassName; /* Assume this exists and is for example @"Foo" */
Class aClass;
aClass = NSClassFromString(myClassName);
object = [[myClass alloc] init];
... if you do NOT KNOW the class at the time of writing the code.
or do this:
object = [[Foo alloc] init];
... if you DO KNOW the class at the time of writing the code.
Use NSClassFromString() instead of objc_getClass for compatibility reasons,
unless you are writing non-GNUstep/Cocoa - pure ObjectiveC code.
> since I'm used to static methods as they're implemented in C++ and Java, and
> forgot that class methods in Obj-C realy are just instance methods of a
> Class object. Got some unlearning to do, it seems...
>
Be pre pared for more differences ;-)
Regards,
Stefan Urbanek
--
http://stefan.agentfarms.net
First they ignore you, then they laugh at you, then they fight you, then
you win.
- Mahatma Gandhi