Как ссылаться на частную переменную экземпляра в main.m - PullRequest
0 голосов
/ 16 октября 2019

Я склоняюсь к target-c, и, как показано ниже в коде, я создал интерфейс с частным разделом переменных экземпляра. В main.m была создана переменная экземпляра указателя, как показано ниже. то, что я хочу знать, это как отправить сообщение одной из переменных частного экземпляра? Что-то вроде следующего:

[ptr->_address XXX]..IS IT POSSIBLE

2- и как инициализировать переменные частного экземпляра, используя

[[xxx alloc] initWithxxx]……IS IT POSSIBLE??

main.m

    MeAsImpl *ptr = [[MeAsImpl alloc] initWithCountry:@"DEU" andCity:@"KA" andAddress:@"xyzstrasse7"];

    NSLog(@"chip:[ %@ ]", ptr->_address);
    NSLog(@"chip:[ %p ]", structChipInitializerSegment);
    NSLog(@"chip:[ %@ ]", structChipInitializerSegment->chipName.self);
    NSLog(@"chip:[ %p ]", structChipInitializerSegment->chipName.self);
    NSLog(@"chip:[ %p ]", structChipInitializerSegment->numOfTotalChannels);

.h :

#import "ProtocolKidsSchedules.h"
#ifndef MeAsImpl_h
#define MeAsImpl_h

#endif /* MeAsImpl_h */

@interface MeAsImpl : NSObject<ProtocolKidsSchedules> {
    id<ProtocolKidsSchedules> _signee;
   NSString *_country;
    NSString *_city;
    NSString *_address;
}

@property (nonatomic, retain) id<ProtocolKidsSchedules> signee;
@property (nonatomic, retain) MeAsImpl *owner;
@property (nonatomic, retain)  NSString *country;
@property (nonatomic, retain)  NSString *city;
@property (nonatomic, retain)  NSString *address;

-(NSString *) signeeOfTheContract: (id<ProtocolKidsSchedules>) signee;
-(id) initWithCountry: (NSString *) country andCity: (NSString *) city andAddress: (NSString *) address;
-(id) initWithOnlyCity: (NSString *) city;
-(id) initWithOnlyAddress: (NSString *) address;

@end

.m

#import <Foundation/Foundation.h>
#import "MeAsImpl.h"

@implementation MeAsImpl
@synthesize country, city, address;

-(BOOL)areChoresCompleted:(BOOL)completed {
   return completed;
}

-(BOOL)areHomeWorkCompleted:(BOOL)completed {
    return completed;
}

-(BOOL)doDerserveCookies:(BOOL)doDeserve {
        return doDeserve;
}

-(NSString *)signeeOfTheContract:(id<ProtocolKidsSchedules>)signee {
   return @"Signee is: ";
}
-(id)initWithCountry:(NSString *)country andCity:(NSString *)city andAddress:(NSString *)address {
    self->_countery = country;
    self->_city = city;
    self->_address = address;
    return self;
}

-(id)initWithOnlyCity:(NSString *)city {
    self->_city = city;
   return self;
}
-(id)initWithOnlyAddress:(NSString *)address {
    self->_address = address;
    return self;
}

@end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...