Note that there are some explanatory texts on larger screens.

plurals
  1. POFilling an NSMutableArray with a Set of Classes and Then Getting them Back
    primarykey
    data
    text
    <p>Hopefully I can make this clear, but I am new to Objective-C and to be honest not great with Arrays in the first place.</p> <p>So, I have a Singleton class (called SingletonState) that I am using to pass variables around my app (please can we leave the whether I should use Singleton classes out of this - I will fix that later). In this class, I have an NSMutableArray (called arrayMyEvents). I have also created a class that I am going to store a list of events (called EventClass). When the user logs in, I call a web service and get back 3 strings. The 3rd string is a comma separated list of value. I parse the data and populate the custom class EventClass. I then add this class to the SingletonState.arrayMyEvents. </p> <p>I have all of this working. I can go to another ViewController and access the "count" of items in arrayMyEvents.</p> <p>PROBLEM: I now want to edit one of the ScheduledEventsClass"es" in my array. How do I get access to it and edit some of the properties and update the one in my SingletonState class?</p> <p>Here is some of the code, that I've tried:</p> <pre><code>NSString *sWebServiceEvents = [[NSString alloc] initWithFormat:@"%@", [result objectAtIndex:2]]; if ( [ sWebServiceEvents isEqualToString:@"NULL" ] != true ) { NSArray *arrayEvents = [sWebServiceEvents componentsSeparatedByString:@","]; // If the array has not been initialized they initialize it. if (sharedState.arrayMyEvents == nil) { sharedState.arrayMyEvents = [[NSMutableArray alloc ] init ]; } for (NSString * sEvent in arrayEvents) { // Set equal to the value of the array (the Event Number) at the same // position as the row that we are being asked to return a cell/row for. EventClass *eventClass = [[EventClass alloc] retain]; eventClass.sEvent = sEvent; [ sharedState.arrayEvents addObject:eventClass ]; } NSLog(@"LoginView - sharedState.arrayMyEvents Count: %d", [sharedState.arrayMyEvents count]); } </code></pre> <p>Here is me trying to access it in another ViewController:</p> <pre><code>EventClass *eventClass = [sharedState.arrayMyEvents objectAtIndex:row ]; NSLog(@"eventClass.sEventNumber: ", eventClass.sEventNumber); eventClass.sLocation = @"Jason's Big Location"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload