English 中文(简体)
在某些情况下,子类可可不意味着子类iv?
原标题:Subclassing Cocoa means no subclass ivars in some cases?

问题一般来自<代码>本身 = [超中]。

如果Im子分类的NSSomething和我的内分法的回归物体不同类别,那么,这是否意味着我无法在我的子流中拥有自己的第iv,仅仅因为自封的将指不同类别?

如果我的发言是错误的,请你举几个例子。

民主党:使我的问题更加准确。

@implementation Base
-(id) init
{
    return [NSNumber numberWithBool:YES];
}
@end

@interface Child : Base
{
int myVeryOwnVar;
}
- (id) init;
- (void) dump;
@end
@implementation Child
- (id) init
{
self = [super init];
myVeryOwnVar = 5;

return self;
}
@end

Child *p = [[Child alloc] init];
[p dump];

这显然在向<代码>p标的发送电文上坠毁,因为它现在有NSNumber<>/code>,并且不作为倾销信息。 因此,我失去了对我的VeryOwnVar的控制,更糟糕的是,我会发生泄漏和坠毁事件。

最佳回答

简言之,当打电话到[超级 init]时,实际上有其隐藏的参数( un),而这正是您的班子所确定的目标。 这些缩略语已经存在,但你通过附在后面的物体(<>条码:自封/代码>),而没有这样做。 <>代码>init>/code>does not set up ivars, but but rather initializes them with Value.

www.un.org/Depts/DGACM/index_spanish.htm 几乎在所有情形下,无论在何种情况下,均将回到相同的<条码>、自封/代码>或<条码>。

更详细(可能更准确)描述见

问题回答

The self = [super init] will not return an object of different class, although it can return an instance of the class that differs from the calling instance. However, it will always be of class NSSomething, or a subclass of NSSomething, and you are always able to have your own instance variables.





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...