English 中文(简体)
培养阶级成员的财产并加以综合
原标题:making class members properties and synthesizing them

如果某类成员不需要获得或固定的职能,那么他们的财产和综合财产就毫无意义了吗?

问题回答

即便这些财产是在执行之外获得的,也往往有助于执行本身。

举例来说,你已经投了票。

@interface SomeObject : NSObject {
    NSThing *thing;
}
@end

@implementation SomeObject

- (id)init {
    if((self = [super init]))
        thing = [[NSThing someThing] retain];
    return self;
}

- (void)someMethod {
    if(thing)
        [thing release];
    thing = [[NSThing someOtherThing] retain];
}

// etc etc

@end

为什么你们想对是否分配了<代码>thing>、thing、将其留给其他部分以及随后的retain进行检查。 当你能够干:时:

- (id)init {
    if((self = [super init]))
        [self setThing:[NSThing someThing]];
    return self;
}

- (void)someMethod {
    [self setThing:[NSThing someOtherThing]];
}

如果你不想让这些财产在贵阶层之外获得,你就可以使用一类财产。

@interface SomeObject ()
@property (retain) NSThing *thing;
@end

页: 1





相关问题
How do you create UIBarButtonItems with a radio interface?

I have a UIToolbar that needs three buttons in a radio style, meaning that of the three, only one button can be pushed at a time. The documentation makes reference to the possibility of setting up ...

iPhone settings bundle

I want to allow the user to enter a valid date using the iPhone’s settings application. I have experimented with many of the PreferenceSpecifiers data node types including date. I have two issues: ...

Circular #import/@class problem in ObjectiveC

I m going to use an example to properly illustrate my confusion. I can t quite wrap my head around this. In Cocoa touch, we have UIViewController and its subclass, UINavigationController. Now, UIVC ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Cocoa-Touch: issue looping MPMoviePlayerController

I have an app which has to load some data at startup, so I want to display a splash-screen animation. I m using the MPMoviePlayerController to play a m4v file. The movie has it s background set to [...

Iphone sequential animation with setAnimationDelay

I m trying to chain animation events. The application I m coding for work has a multiple choice quiz. First you pick your multiple choice answer. The quiz view fades away. Then a label ("correct" or "...

热门标签