我已經構建了一個對象數組,這是從我之前編寫的一個類創建的。我只是想獲得一些類變量,而通過數組循環:不良訪問代碼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'? –