blog main image

Twitter Quiz = Twiz

I built this app for App Raptors (a client) while attending Dev Mountain. It gets your twitter feed and quizes you on who said what rewarding points for correct answers. Even though I personally believe Javascript will devour the world wide web... it doesn't hurt to put a little native experience in your toolbelt right?

I did it all. From design to development, this was my baby. I didn't handle authentication of users or create my own database and api -- big shout out to Parse for that stuff -- but I did get to learn quite a bit about the exciting world of native iOS.

"any application that can be written in JavaScript, will eventually be written in JavaScript" Atwood's Law
Wanted to mention I haven't touched an iPhone app since graduating because I handed it off to the firm I built it for. I had help along the way from mentors were great in helping me pass roadblocks, but like the quote above, I just think javascript and web based API are going to be more usefull to me over time. That being said and I worked extensively with the Parse and Twitter API while including my own game logic in a way that the user can just keep playing seemelessly without ever thinking twice. KEEP IN MIND: This was my first iPhone app, still relatively new to development. I don't profess this to be clean or awesome code... but it did work :)

        #pragma mark - Answers and Score

        -(void) generateRandomNumberArray {
          int objectsInArray = [self.possibleAnswerBucketArray count]; // makes it so you don't get numbers higher than what is currently in there

          NSInteger randomNumber = (NSInteger) arc4random_uniform(objectsInArray); // picks between 0 and n-1
          if (self.mutableArrayContainingNumbers) {
            if ([self.mutableArrayContainingNumbers containsObject: [NSNumber numberWithInteger:randomNumber]]){ // crashes here when you don't have more than 4 possible answers to choose from
            [self generateRandomNumberArray]; // call the method again and get a new object
          } else {
            // end case, it doesn't contain it so you have a number you can use
            [self.mutableArrayContainingNumbers addObject: [NSNumber numberWithInteger:randomNumber]];
            if ([self.mutableArrayContainingNumbers count] != 3) {
              [self generateRandomNumberArray];
            }
          }

        } else { // runs the first time
          NSMutableArray *mutableArrayContainingNumbers = [NSMutableArray new];
          [mutableArrayContainingNumbers addObject: [NSNumber numberWithInteger:randomNumber]];
          self.mutableArrayContainingNumbers = mutableArrayContainingNumbers;
          [self generateRandomNumberArray];
        }

      }

      - (NSMutableArray *) requestActivePossibleAnswers:(MyActiveTweet *)activeTweet{

        [self generateRandomNumberArray];

        NSMutableArray *activePossibleAnswers = [NSMutableArray new];
        for (int i = 0; i < [self.mutableArrayContainingNumbers count]; i++)
        {
          NSNumber *possibleAnswerRandomNumber = self.mutableArrayContainingNumbers[i];
          // if error's here it's because you don't have any possibleAnswers
          NSDictionary *possibleAnswer = [self.possibleAnswerBucketArray objectAtIndex:possibleAnswerRandomNumber.integerValue];
          [activePossibleAnswers addObject:possibleAnswer];
        }

        self.mutableArrayContainingNumbers = nil;
        NSNumber *points = [NSNumber numberWithInteger:5];
        NSDictionary *correctAnswer = [[NSDictionary alloc]initWithObjectsAndKeys:
        activeTweet.correctAnswerPhotoURL, possibleAnswerPhotoURLKey,
        activeTweet.correctAnswerID,possibleAnswerAuthorKey,
        points, tweetPointsKey, nil];

        for (NSDictionary *answer in activePossibleAnswers) {
          if ([answer[possibleAnswerAuthorKey] isEqualToString:correctAnswer[possibleAnswerAuthorKey]]) {
            NSLog(@"this answer is a duplicate");
            return [self requestActivePossibleAnswers:activeTweet];
          }
        }

        NSInteger randomIndexNumber = (NSInteger) arc4random_uniform(4); // pics random number n-1
        [activePossibleAnswers insertObject:correctAnswer atIndex:randomIndexNumber];

        return activePossibleAnswers;
      }