Why is this unusual Objective-C design design a bad idea?

Recently I joined a new project with a large existing code base, which often uses a template that I have never seen in practice or in any of the literature.

As an example:

ClassA.h

@interface ClassA : UIViewController
@end

ClassA.m

@interface ClassA ()
@property (nonatomic,weak) IBOutlet UILabel *labelOne;
@property (nonatomic,weak) IBOutlet UILabel *labelTwo;
@end

@implementation ClassA
//...
@end

ClassAHelper.h

@interface ClassAHelper : NSObject
- (void)configureClassA:(ClassA *)classA;
@end

ClassAHelper.m

// here the 'interesting' bit
@interface ClassA ()
@property (nonatomic,weak) UILabel *labelTwo;
@end

@implementation ClassAHelper

- (void)configureClassA:(ClassA *)classA {
    classA.labelTwo.text = @"wtf?";
}

@end

Thus, classes are declared without (or a very small) external interface, and access to these class properties is achieved by declaring these properties that the access class is interested in by the anonymous category inside the access class implementation file.

, Objective-C , , ivars . , .m #, .h. , , .m . . , , , , .

, : , ? , , , ( - , ", , ?" ).

+4
2

, , , , , .

"private" () .

, , externaly .

" , ", , , , , SDK , , , - Whatever+Private.h, .

+2

, , , , :

ClassA-Private.h:

#import "ClassA.h"

@interface ClassA ()
@property (nonatomic,weak) IBOutlet UILabel *labelOne;
@property (nonatomic,weak) IBOutlet UILabel *labelTwo;
@end

#import ed ClassA.m ClassAHelper.m.

+1

Source: https://habr.com/ru/post/1545193/


All Articles