用oc写一个带姓名,年龄,电话号码,地址的通讯录列表
时间: 2024-06-12 22:04:47 浏览: 160
#import <Foundation/Foundation.h>
@interface Contact : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *phone;
@property (nonatomic, strong) NSString *address;
@property (nonatomic, assign) NSInteger age;
@end
@implementation Contact
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Contact *c1 = [[Contact alloc] init];
c1.name = @"张三";
c1.phone = @"13888888888";
c1.address = @"北京市海淀区";
c1.age = 25;
Contact *c2 = [[Contact alloc] init];
c2.name = @"李四";
c2.phone = @"13999999999";
c2.address = @"上海市浦东新区";
c2.age = 30;
NSArray *contacts = @[c1, c2];
for (Contact *contact in contacts) {
NSLog(@"姓名:%@,年龄:%ld,电话号码:%@,地址:%@", contact.name, contact.age, contact.phone, contact.address);
}
}
return 0;
}
阅读全文