Note that there are some explanatory texts on larger screens.

plurals
  1. POObC : app crashes after returning NSMutableArray?
    primarykey
    data
    text
    <p>I am new to ObC and have a problem that i just cant fix. There may be other issues as well but the main issue is this:</p> <ol> <li>Starting the app</li> <li>Press button = load new view</li> <li>In the new viewDidLoad i call another object/function and send a NSMutableArray</li> <li>Process data and send back a NSMutableArray</li> <li>App crash, see comment where. Most often when i go back and back again but sometimes the first time</li> </ol> <p>As i am new to this i guess i do a lot of this wrong but could someone nice take a look at the code and give me some advice. I would assume i have problem with releasing something.</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSLog(@" "); NSLog(@"viewDidLoad "); NSLog(@" "); NSLog(@"&gt;&gt;Processing prepareGame&lt;&lt;"); NSMutableArray *propArray1 = [[NSMutableArray alloc] initWithObjects:@"9999", nil]; //Init with dummy numbers AccessPropertiesFile *readMyProperties = [AccessPropertiesFile new]; //Init function call to read file NSLog(@"Prepare to call readProperties"); propArray1 = [readMyProperties readPropertiesFile:propArray1]; NSLog(@"Back from readProperties:error after this"); /* for (NSString *element in propArray1) { NSLog(@"Elements in prop2Array; %@", element); } */ [readMyProperties release]; [propArray1 release]; } -(NSMutableArray *)readPropertiesFile:(NSMutableArray *)readDataArray { NSLog(@"Processing readProperties"); // For error information NSError *error; //Prepare File Manager NSString *filePath = [self dataFilePath]; NSFileManager *fileMgr; fileMgr = [NSFileManager defaultManager]; NSArray *propertiesArray = [NSArray alloc]; //Alloc array //Check from what module the call is coming from to ecide what to do if ([fileMgr fileExistsAtPath: filePath] == NO) { NSLog (@"File not found"); //File does not exists, this is the first time the game starts //Set up default parameters NSString *fileString =@"0\n30\n30\n10\n1\n1\n1\n2\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n"; // Write default parameters to file [fileString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&amp;error]; propertiesArray = [fileString componentsSeparatedByString:@"\n"]; // each line, adjust character for line endings } else { //File exists NSLog (@"File exists"); NSString *fileString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; // reads file into memory as an NSString propertiesArray = [fileString componentsSeparatedByString:@"\n"]; // each line, adjust character for line endings } //Clean readDataArray [readDataArray removeAllObjects]; //Populate return array for (NSString *element in propertiesArray) { //NSLog(@"Elements in propertiesArray; %@", element); [readDataArray addObject:element]; } NSLog(@"readDataArray: %@", readDataArray); [propertiesArray release]; [readDataArray autorelease]; NSLog(@"returning from readProperties"); return readDataArray; } @end </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.
    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