I am trying to build a storage class for my iPhone app. The storage class is for storing a list of food orders and each order has a food name and price. In the app, I want to store it in order into an 2 dimension array named orders when I press a button at my food menu.I am a Java user, and new to Objective-C. What I want to build is a storage class which is similar to java’s ArrayList class, and the Storage.m class holds the food name and price.
I have some code already, but it keeps shows up with this error: “Type of property ‘orders’ does not match type of accessor ‘setOrder’ ” in my Storages.h class.
Storage.h
#import <Foundation/Foundation.h>
@interface Storage : NSObject{
NSString *name;
NSInteger *price;
}
@property (nonatomic)NSString *name;
@property (nonatomic)NSInteger *price;
@end
Storage.m
#import "Storage.h"
@implementation Storage
@synthesize name;
@synthesize price;
@end
Storages.h
#import <Foundation/Foundation.h>
#import "Storage.h"
@interface Storages : NSObject{
Storage *order;
NSMutableArray *orders;
@property (nonatomic) NSMutableArray *orders; // error "Type of property 'orders' does not match type of accessor 'setOrder'"
-(void) setOrders:(Storage *)order;
-(NSMutableArray *) orders;
@end
Storages.m
#import "Storages.h"
@implementation Storages
@synthesize orders;
-(void) setOrders:(Storage *)oneOrder{
[orders addObject: oneOrder];
}
-(NSMutableArray *) orders;{
return orders;
}
@end
Since you have a property called “orders”, the function “setOrders” is overriding the setter method of that property.So to make it work you’ll have to change the name of setOrders: function to something like addOrder:(Storage *)order.