objective-c - 如何在 main.m 中引用私有实例变量
问题描述
我正在学习objective-c,如下面的代码所示,我创建了一个带有私有实例变量部分的接口。在 main.m 中,创建了一个指针实例变量,如下所示。我想知道的是如何向私有实例变量之一发送消息?如下所示:
[ptr->_address XXX]..IS IT POSSIBLE
2-以及如何使用初始化私有实例变量
[[xxx alloc] initWithxxx]……IS IT POSSIBLE??
主文件
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
解决方案
推荐阅读
- python - 如何从熊猫数据框中获取单元格值
- swift - 如何基于字符串检测数据中的编码?
- excel - 满足条件后插入具有序号的新行
- javascript - 根据日期合并/组合数组数据而不重复角度
- go - 下载模块的原始代理
- node.js - 无法运行 puppeteer 获取请求错误父级
- django - 在 Django REST 框架中检索不相关的对象
- python - 在 Linux 上使用 Python zipfile 提取时出现 OSError 无效参数
- python - 如何获取网站上所有文章的链接?
- java - 我可以将字符串变量从 eclipse (java) 发送到 powershell 脚本吗