Note that there are some explanatory texts on larger screens.

plurals
  1. PONSString from a class returning null after assignment?
    text
    copied!<p>I have a problem with assigning values to a string and then getting them back. The string is a property of a class, because I need it to carry over to other view controllers. (I have tried Core Data, but it didn't work either and this seemed simpler.)</p> <p>The class for the strings is this:</p> <pre><code>.h @interface GameInformation : NSObject @property (nonatomic, retain) NSString *word; @property (nonatomic, retain) NSString *mode; @end .m @implementation GameInformation @synthesize mode = _mode; @synthesize word = _word; @end </code></pre> <p>Pretty simple. The relevant code in app delegate:</p> <pre><code>GameInformation *gameInfo = [GameInformation alloc].init; optionsView.gameInfo = gameInfo; oneBox.gameInfo = gameInfo; twoBox.gameInfo = gameInfo; </code></pre> <p>And so on, until I've got all the controllers covered. Options view is where I set the value for the strings, and test those values.</p> <pre><code>GameInformation *info = [self gameInfo]; UISegmentedControl *selectMode = [self mode]; UISegmentedControl *gameWord = [self word]; if (selectMode.selectedSegmentIndex == 0) { info.mode = @"regular"; } else if (selectMode.selectedSegmentIndex == 1) { info.mode = @"wordTap"; } if (gameWord.selectedSegmentIndex == 0) { info.word = @"regular"; } else if (gameWord.selectedSegmentIndex == 1) { info.word = @"hat"; } else if (gameWord.selectedSegmentIndex == 2) { info.word = @"dog"; } else if (gameWord.selectedSegmentIndex == 3) { info.word = @"book"; } else if (gameWord.selectedSegmentIndex == 4) { info.word = @"bus"; } else if (gameWord.selectedSegmentIndex == 5) { info.word = @"cup"; } else if (gameWord.selectedSegmentIndex == 6) { info.word = @"pig"; } NSLog(@"%@", info.mode); NSLog(@"%@", info.word); </code></pre> <p>And the log comes out as null when those are passed over. I have tried [info setWord:@"regular"]; and [info setMode@"regular"]; but those didn't work either.</p> <p>I haven't tried using the strings in the one box, two box, etc. controllers yet, because the test return null.</p> <p>So. What am I doing wrong? Or am I barking up the wrong tree? And, like I said earlier, trying to use core data for this didn't work and this seemed like a simpler approach.</p> <p>Thanks in advance!</p> <p>EDIT: Thank you all for the quick comments! I did a NSLog on info and it is indeed null. I also changed the declarations to copy instead of retain, and changed the dot notation in the alloc statement. The alloc statement is in the app delegate's didFinsihLaunchingWithOptions. Is that the wrong place?</p> <p>Thanks again for the help!</p>
 

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