我已经构建了一个对象数组,这是从我之前编写的一个类创建的。我只是想获得一些类变量,而通过数组循环:不良访问代码1:访问对象实例变量
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *medicalCenters = [(AppDelegate *)[[UIApplication sharedApplication] delegate] medicalCenters];
for (MedicalCenter *row in medicalCenters){
NSString *latitude = row.MCLatitude;
NSLog(@"%@", latitude);
}
}
我创建这个样子的类文件:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MedicalCenter : NSObject
{
CLLocationCoordinate2D _coordinate;
}
@property (nonatomic, strong) NSString *medicalCenter;
@property (nonatomic, assign) NSString *MCLatitude;
@property (nonatomic, assign) NSString *MCLongitude;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithName:(NSString *)medicalCenter coordinate:(CLLocationCoordinate2D)coordinate;
@end
每当我建立起来的NSString *latitude = row.MCLatitude
,我得到了该消息: Bad_excess代码:1
但是,当我只列出阵列medicalCenters中的对象,我可以看到他们所有............ 我错过了重要的东西吗?
感谢 塞巴斯蒂安
为什么在'MCLatitude'和'MCLongitude'中使用'assign'? –