Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HyperSnake

macrumors member
Original poster
Jan 5, 2009
74
0
Switzerland
I'm doing a flip-side application (not using the template) where I have 3 classes and the app delegate. They are:

RootViewController(.h and .m)
FrontSideViewController(.h and .m)
BackSideViewController(.h and .m)

Each have their own view. In FrontSideViewController I have declared a dictionary loading contents from a .plist file. My problem is: I don't know how I can change the contents of this dictionary while inside BackSideViewController. I'm showing a TextView and a Label in the FrontSideView(loaded from the class FrontSideViewController) and I want to be able to change the dictionary from which the TextView gets it's data from in the BackSideView(loaded from the class BackSideViewController).

In short: How do I change the value of dictionary in class X while inside class Y?

I would appreciate any help or possible alternatives. If it is not possible, how could I then do this?

- Ben
 

bboyjayz

macrumors member
Mar 20, 2009
55
0
maybe you can code ascessor (ascesseur in french), in the class containing the dictionnary to modify, create 2 methods, first one to have access to the variable , for exemple:
-(NSArray*)getDictionnary{
return myDictionnay;
}

and the second one to modify your dictionnary, like this:
-(void)setDictionnaryTo:(NSArray*)newDico{
myDictionnary = newDico;
}

then, in the class where you want to modify the variable,
just create an object of your first class, and call setDictionnary to modify your variable "myDictionnary"

Maybe property does this work, but i'm not used to use it, i prefere ascessor, more used in other language like C++, Java etc...

I hop my answer will help you ...
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
There are number of ways to approach this issue. First, you could create accessors for the dictionary in your first view controller and that would allow you to use them in the second view controller. Other solutions include moving the dictionary to the root view controller or the app delegate or as a global variable. But if you want to follow the MVC paradigm more closely, you probably want to define a new model class that deals with the dictionary.

Maybe property does this work, but i'm not used to use it, i prefere ascessor, more used in other language like C++, Java etc...
Using a @property declaration and a @synthesize are not really an alternative to an accessor, they are accessors. They are just a shorthand that let's the compiler do all the heavy-lifting so you don't have to. Minimizes errors that way, too.
 

bboyjayz

macrumors member
Mar 20, 2009
55
0
Thank you to the information about @property, but it is one thing i don't understand, it is parameter like "retain" or "nonatomic", wich obliged user to have a property for Object, but if i want a property for a non-Object variable like an int, how do i do ?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.