好像我有问题,不知道我是否做对了,因为我刚刚开始目标 c。
现在我有两个文件
商店.h
#import<Foundation/Foundation.h>
#import<MapKit/MapKit.h>
@interface Stores: NSObject
@property(nonatomic,strong) NSString *storeName;
@property(nonatomic,strong) NSMutableArray *MenuItems;
@end
商店.m
#import "Stores.h"
@synthesize storeName,MenuItems;
@end
菜单.h
#import<Foundation/Foundation.h>
@interface Menu: NSObject
@property(nonatomic,strong) NSString *MenuItemDescription;
@property(nonatomic) int MenuItemPrice;
@end
菜单.m
#import "Menu.h"
@synthesize MenuItemDescription,MenuItemPrice;
@end
视图控制器.m
#import "ViewController.h"
#import "Stores.h"
#import "Menu.h"
@interface ViewController ()
@end
@implementation ViewController
NSMutableArray *stores;
-(void) viewDidLoad
{
[super viewDidLoad];
stores = [[NSMutableArray alloc]init];
Stores *store = [[Stores alloc]init];
[store setStoreName:@"Store1"];
Menu *menuItem = [[Menu alloc]init];
[menuItem setMenuItemDescription:@"Item1"];
[menuItem setMenuItemPrice: 7]
[store.MenuItems addObject:menuItem]; //won't add menuItem to store.MenuItems
[stores addObject:store];
}
@end
所以它最终不会添加任何对象来存储。如果我在调试中运行它,它会说 MenuItems 有零个对象。我知道我做错了什么,但就像我说我是 iOS 新手。