mardi 30 août 2016

Randomizing array in objective C, Xcode

I know this has been answered before but none of the answers works for me. Or I don't know hot to implement them.

i have a new code with method from gamekit but still nothing.

this is an error screenshot

http://ift.tt/2ccfMq0

This is my .h

    #import <UIKit/UIKit.h>
    #import "Accounts/Accounts.h"
    @import GameKit;


    @interface ViewController : UIViewController {


        IBOutlet UIImageView *image;
        IBOutlet UILabel *label;
        IBOutlet UITextView *description;

        NSArray *tasks;
        NSArray *shuffledTasks;

    }




- (IBAction)random:(id)sender;



@end

And this is my .m

#import "ViewController.h"


@import GameKit;


@interface ViewController ()


@end

@implementation ViewController



- (void)viewDidLoad {

    tasks = @[@0, @1, @2,  @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21, @22];

    [self shuffle];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

NSInteger text;
int x=0;
int z=9999;


-(void)shuffle
{
  shuffledTasks = [[GKRandomSource sharedRandom] arrayByShufflingObjectsInArray:tasks];
    }


-(void)reset{
    if (x>22) {
        x=0;
        [self shuffle];
    }
}


- (IBAction)random:(id)sender {

    text = [[shuffledTasks objectAtIndex:x] integerValue];
    x++;


        switch (text) {


            case 0:
                //something
                z=0;

                [self reset];
                break;

            case 1:
                //something
                z=1;
                [self reset];
                break;

            case 2:
                //something
                z=2;
                [self reset];
                break;

            case 3:
                //something
                z=3;
                [self reset];
                break;

            case 4:
                //something
                z=4;
                [self reset];
                break;
            case 5:
                //something
                z=5;
                [self reset];
                break;
            case 6:
                //something
                z=6;
                [self reset];
                break;
            case 7:
                //something
                z=7;
                [self reset];
                break;
            case 8:
                //something
                z=8;
                [self reset];
                break;
            case 9:
                //something
                z=9;
                [self reset];
                break;
            case 10:
                //something
                z=10;
                [self reset];
                break;

            case 11:
                //something
                z=11;
                [self reset];
                break;
            case 12:
                //something
                z=12;
                [self reset];
                break;
            case 13:
                //something
                z=13;
                [self reset];
                break;
            case 14:
                //something
                z=14;
                [self reset];
                break;
            case 15:
                //something
                [self reset];
                break;
            case 16:
                //something
                z=16;
                [self reset];
                break;
            case 17:
                //something
                z=17;
                [self reset];
                break;
            case 18:

                 //something

                z=18;
                [self reset];
                break;

            case 19:

                //something

                z=19;
                [self reset];
                break;

            case 20:

                //something

                z=20;
                [self reset];
                break;

            case 21:

                //something

                z=21;
                [self reset];
                break;

            case 22:

                //something

                z=22;
                [self reset];
                break;

            default:
            break;

        }  }



- (void)dealloc {
    [bannerView release];
    [cube1 release];
    [cube2 release];
    [super dealloc];
}
    @end




Aucun commentaire:

Enregistrer un commentaire