objective c - While (not) loop freezes app -


my while loop doesn't seem work. when loading view, app freezes. when delete part of code, containing while loop, app won't freeze.

what i'm searching piece of code cause same array not chosen twice.

@interface thirdviewcontroller ()  @end  @implementation thirdviewcontroller  ... nsstring * answer = @""; nsarray * ramarray;  ...  - (void)newquestion {     nsstring * pliststring = [[nsbundle mainbundle] pathforresource:@"questions" oftype:@"plist"];     nsmutablearray * plistarray = [[nsmutablearray alloc]initwithcontentsoffile:pliststring];     nsarray *plistrandom = [plistarray objectatindex: random()%[plistarray count]];      while (![plistrandom isequal: ramarray])     {         nsarray *plistrandom = [plistarray objectatindex: random()%[plistarray count]];     }      ramarray = plistrandom;     ... }  - (void)check:(nsstring*)choise {     ...      if ([choise isequaltostring: answer])     {         ...         [self newquestion];     } }  - (ibaction)ansbuta:(id)sender {     uibutton *resultbutton = (uibutton *)sender;     nsstring *click = resultbutton.currenttitle;      [self check:click]; } 

my guess because re-declare plistrandom within while loop, inner-declared variable may out of scope @ point while conditionis evaluated. problem think scoping issue, change loop , see if works:

while (![plistrandom isequal: ramarray]) {     plistrandom = [plistarray objectatindex: random()%[plistarray count]]; } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -