Creating class objects objective c -


i started transferring java knowlege objective c quite , got making apps xcode too. have few things i'm confused though. first of in java when i'm making top down games , need shoot projectile, like:

public class bullet{     int x,y;     public bullet(double x, double y){         this.x = x;          this.y = y;     }     public void tick(){         //logic goes in here move bullet     } }  

then i'd have class arraylist:

public class mainclass{     arraylist<bullet> bulletlist;     public main(){         //create arraylist takes bullet objects         bulletlist = new arraylist<bullet>();         //add new bullet @ coordinate (100,100)         bulletlist.add(new bullet(100,100));        }      //gameloop(we'll pretend gets called every millisecond or so)     public void gameloop(){         //loop through list         for(int = 0; < bulletlist.size(); i++){             //run method tick() @ current index             bulletlist.get(i).tick();         }     } } 

so... question how translate code objective c. or in other terms, how create arraylist similar 1 in example creates object of class , loop through , call loop method or whatever method create inside.

objective-c has no generics, unlike java. wouldn't make sense, since objective-c dynamically typed (for part). instead, nsmutablearray , nsarray store instances of nsobject or subtypes thereof (similar arraylist<object> in java).


something should started.

@interface mainclass()  @property(nonatomic, strong) nsmutablearray *bullets;  @end  @implementation mainclass  - (id)init {     if (self = [super init]) {         self.bullets = [nsmutablearray array];         [self.bullets addobject:[[bullet alloc] initatx:100 y:100]];     }      return self; }  - (void)gameloop {     [self.bullets makeobjectsperformselector:@selector(tick)]; }  @end 

Comments