[Source] Remake of MixUp

Discussion in 'iOS Development' started by JoshuaCaputo, Apr 15, 2010.

  1. JoshuaCaputo

    JoshuaCaputo New Member

    Joined:
    Aug 2, 2008
    Messages:
    605
    Likes Received:
    0
    Device:
    iPod touch
    Oh god, if anyone here remembers iAppaday from way back then in those dark times let me know.

    Well a while ago I made one of his apps "MixUp".

    I figured I would share some of the ways I did the sliding and swiping and get some feedback on the way you guys handle it. Mine might seem a little wonky.

    Please Register or Log in to view images

    Attached Files:

  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    I went ahead and got rid of your memory leaks. In LyttiViewController, I edited the -readPlist method to this

    [OBJC]- (IBAction)readPlist
    {
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSString *filePath = [path stringByAppendingPathComponent

    Please Register or Log in to view images

    "Words.plist"];
    NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

    int number;
    number = 1 + arc4random() %5;
    NSLog(@"%i", number);

    NSString *wordLetter;
    wordLetter = [NSString stringWithFormat

    Please Register or Log in to view images

    "%iletter1", number];
    letter1 = [plistDict objectForKey:wordLetter];

    wordLetter = [NSString stringWithFormat

    Please Register or Log in to view images

    "%iletter2", number];
    letter2 = [plistDict objectForKey:wordLetter];

    wordLetter = [NSString stringWithFormat

    Please Register or Log in to view images

    "%iletter3", number];
    letter3 = [plistDict objectForKey:wordLetter];

    wordLetter = [NSString stringWithFormat

    Please Register or Log in to view images

    "%iletter4", number];
    letter4 = [plistDict objectForKey:wordLetter];

    NSString *theAnswer;
    theAnswer = [NSString stringWithFormat

    Please Register or Log in to view images

    "%iAnswer", number];
    answer = [plistDict objectForKey:theAnswer];

    NSLog(@"%@", answer);

    [plistDict release];

    caption1.text = letter1;
    caption2.text = letter2;
    caption3.text = letter3;
    caption4.text = letter4;

    space1 = [[ NSString alloc ] initWithString:letter1];
    space2 = [[ NSString alloc ] initWithString:letter2];
    space3 = [[ NSString alloc ] initWithString:letter3];
    space4 = [[ NSString alloc ] initWithString:letter4];

    }[/OBJC]

    In the same file, I also changed the checkAnswer method to this:
    [OBJC]- (void)checkAnswer{

    if (IsSwiping == NO){
    NSString *yourAnswer = [[NSString alloc] initWithFormat

    Please Register or Log in to view images

    "%@%@%@%@", space1, space2, space3, space4];
    if ([yourAnswer isEqual: answer]){
    [self correct];
    }
    [yourAnswer release];
    }
    }[/OBJC]

    Also, I don't know why you use arc4random()? There's no reason to use it here. I'm genuinely curious you opted not to use rand() or random().
  3. JoshuaCaputo

    JoshuaCaputo New Member

    Joined:
    Aug 2, 2008
    Messages:
    605
    Likes Received:
    0
    Device:
    iPod touch
    Honestly its because I don't know the difference or benefits of one or the other. I thought arc4random() also incorporated abs(). so it would return 2 instead of 2.3923242423323.

    Is this untrue?
  4. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    all of the functions mentioned in this thread (rand(), random() and arc4random()) return integral values...

    also, absolute value != truncation.

    rand() and random() need to be seeded by you; arc4random() takes care of that itself.

    arc4random() affords you greater range, but that is obviously not relevant in this case. I can't comment on the speed of any of the functions, but that, too, is not really a big deal in this case either.
  5. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    So it seems like arc4random() is ok here because one can avoid to have to seed it.

    I'm really interested in Skylar's opinion.

    Please Register or Log in to view images

  6. JoshuaCaputo

    JoshuaCaputo New Member

    Joined:
    Aug 2, 2008
    Messages:
    605
    Likes Received:
    0
    Device:
    iPod touch
    Glad thats settled. No comments on my code

    Please Register or Log in to view images

    .

Share This Page