Im programming with objective c for ios. I have a problem...i create a class object this is the Item.h
@interface Item : NSObject {
NSString *date;
NSMutableArray *a;
NSMutableArray *b;
NSMutableArray *c;
NSMutableArray *d;
NSMutableArray *e;
NSMutableArray *f;
NSMutableArray *g;}
- (id)init;
- (void)setDate:(NSString *)dateGio;
- (void)adda:(NSString *)i;
- (void)addb:(NSString *)i;
- (void)addc:(NSString *)i;
- (void)addd:(NSString *)i;
- (void)adee:(NSString *)i;
- (void)addf:(NSString *)i;
- (void)addg:(NSString *)i;
- (NSMutableArray *)geta;
- (NSMutableArray *)getb;
- (NSMutableArray *)getc;
- (NSMutableArray *)getd;
- (NSMutableArray *)gete;
- (NSMutableArray *)getf;
- (NSMutableArray *)getg;
@end
and this is the Item.m
#import "MealsItem.h"
@implementation MealsItem
- (id)init {
self = [super init];
if(self) {
NSString *date = @"";
NSMutableArray *a = [[NSMutableArray alloc] init];
NSMutableArray *b = [[NSMutableArray alloc] init];
NSMutableArray *c = [[NSMutableArray alloc] init];
NSMutableArray *d = [[NSMutableArray alloc] init];
NSMutableArray *e = [[NSMutableArray alloc] init];
NSMutableArray *f = [[NSMutableArray alloc] init];
NSMutableArray *g = [[NSMutableArray alloc] init];
}
return self;
}
- (void)adda:(NSString *)i {
[a addObject: i];
}
- (void)addb:(NSString *)i {
[b addObject: i];
}
- (void)addb:(NSString *)i {
[b addObject: i];
}
- (void)addd:(NSString *)i {
[d addObject: i];
}
- (void)adde:(NSString *)i {
[e addObject: i];
}
- (void)addf:(NSString *)i {
[f addObject: i];
}
- (void)addg:(NSString *)i {
[g addObject: i];
}
- (NSMutableArray *)geta {
return a;
}
- (NSMutableArray *)getb {
return b;
}
- (NSMutableArray *)getc {
return c;
}
- (NSMutableArray *)getd {
return d;
}
- (NSMutableArray *)gete {
return e;
}
- (NSMutableArray *)getf {
return f;
}
- (NSMutableArray *)getg {
return g;
}
@end
In this object i save string in the specific array. In my First view (the main of the project) i initialize the object
#import <UIKit/UIKit.h>
#import "Item.h"
@interface First_View : UIViewController {
@public Item *ok;
}
@property (nonatomic, retain) Item *ok;
@end
and in the .m
#import "First_View.h"
#import "Item.h"
@interface First_View ()
@end
@implementation First_View
@synthesize ok;
- (void)viewDidLoad
{
[super viewDidLoad];
ok = [[Item alloc] init];
}
@end
The problem is that i have to read and modify the object initialize in the First_View, using the method of "Item.m", from another class. In the other class i use this
First_View *first = [[First_View alloc] init];
and i try to modify the object but i cant. I can just if i use also
first.ok = [[Item alloc] init];
but i dont want to initialize again the object but use the object already created in the First_View. How is possible to modify the object without initialize again the object??
1, how would you use the integer1? If this was allowed the compiler wouldn't know whether you meant your variable or the integer.