It seems like I have a problem and don’t know if I’m doing this right since I’m just starting objective c.
Right now I have two files
Stores.h
#import<Foundation/Foundation.h>
#import<MapKit/MapKit.h>
@interface Stores: NSObject
@property(nonatomic,strong) NSString *storeName;
@property(nonatomic,strong) NSMutableArray *MenuItems;
@end
Stores.m
#import "Stores.h"
@synthesize storeName,MenuItems;
@end
Menu.h
#import<Foundation/Foundation.h>
@interface Menu: NSObject
@property(nonatomic,strong) NSString *MenuItemDescription;
@property(nonatomic) int MenuItemPrice;
@end
Menu.m
#import "Menu.h"
@synthesize MenuItemDescription,MenuItemPrice;
@end
ViewController.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
So it doesn’t end up adding any object to store.
If I run it in debug it says that MenuItems has zero objects.
I know I’m doing something wrong but like I said I’m new to iOS.
You did not (at least in the code you show) alloc/create/assign MenuItems, so it will still be nil. Calling addObject (or anything) on nil is just a no-op.
Try this