Still working on my flash card-themed app. Completely baffled. Lots of possibly salient info.
I have a version which works flawlessly, both in simulator and on multiple devices. But, I made a mistake when submitting to the App Store (wrong Bundle ID and Name), so I created a new project and copied and pasted the code and storyboard. (I didn't just move the files; I recreated them and copied the code.)
First problem was that it wouldn't build because "duplicate symbol _answers in" RootViewController.o and DescendantViewController.o. And there were 3 such duplicate symbols.
Yes, I have declared NSMutableArray *answers
in the implementation of both my RootVC and DescedantVC, so I concede that's suspect, except.... it's the exact same code as in the version that works.
Nevertheless, I saw an opportunity to clean up my code, so I created a @property (weak, nonatomic) NSMutableArray *answers
in my RootVC and changed the code in the root and descendant View Controllers to reference self.answers
. It compiles without any problems.
It runs in the simulator perfectly. As I've just copied the entire code base to a new project, I test everything - no problems. I'm very excited, so I do all the steps to submit to the App Store, except the last one "Submit for Review."
I want to show off to my friend, so I attach my iPhone 6, compile it, run it and when I select "Play" - crash!
The following line is the culprit.
answers = [self pickWrongAnswersIgnoringCard:questionCard];
Both in the simulator and on the device, the last line of the this method is:
return wrongAnswers;
In both cases, wrongAnswers
is an array with 3 items.
In the simulator, answers
also has 3 items. On my iPhone, answers
is nil.
Does anyone have any idea what this could be? The only thing I can think of is that I created the project that works over a year ago and the one that fails today, so maybe some of the Apple settings in the two projects are different? Otherwise, I'm stumped.
The function, as requested:
-(NSMutableArray *)pickWrongAnswersIgnoringCard:(FlashCard *)questionCard {
NSMutableArray *wrongAnswers = [[NSMutableArray alloc] init];
FlashCard *randomCard;
for (int i=1; i<4; i++) {
do {
randomCard = [self pickARandomCardFromDeck:wrongAnswersSource];
} while ([randomCard.name isEqualToString:questionCard.name] || [wrongAnswers containsObject:randomCard]);
[wrongAnswers addObject:randomCard];
}
return wrongAnswers; // device or simulator, wrongAnswers.count = 3
}
I figured it out, even if I don't fully understand.
I changed from @property (weak, nonatomic)
to @property (strong, nonatomic)
.
That solved it for me.
Works on both simulator and device now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.