Load custom class properly
Posted
by
LinusAn
on Stack Overflow
See other posts from Stack Overflow
or by LinusAn
Published on 2012-06-23T08:31:55Z
Indexed on
2012/06/23
9:16 UTC
Read the original article
Hit count: 118
I have a custom class which I want to "load" inside the firstViewController and then access it from other classes by segues. My Problem is, I can't even access and change the instance variable inside the firstViewController. Somehow I'm "loading" it wrong. Here is the code I used until now:
inside viewController.h
@property (strong, nonatomic) myClass *newClass;
inside viewController.m
@synthesize newClass;
I then try to access it by:
self.newClass.string = @"myString";
if(newClass.string == @"myString"){
NSLog(@"didn't work");
}
Well, I get "didn't work". Why is that? When I write
myClass *newClass = [myClass new];
It does work. But the class and its properties gets overwritten every time the ViewController loads again.
What would you recommend? Thank you very much.
© Stack Overflow or respective owner