Showing posts with label Php. Show all posts
Showing posts with label Php. Show all posts

Monday, December 13, 2010

For/Foreach -> php vs objective-c

Lets start with a short Post about for/foreach PHP vs Objective-C
 To loop through an array in php is very simple:

foreach($arrData as $key => $value){
    //do something...
}

or

for($i = 0; $i < count($arrData); $i++){
    //do somethin... 
}

In Objective-C you have similar possibilities but you have to be sure what kind of object you are dealing with e.g. NSDictionary* or NSArray*

To get an Element of these two types you do as follows:

NSDictionary

NSDictionary* arrData = ...;
 [arrData objectForKey:@"id"];

Loop

for (NSString* key in arrData) {
        id value = [arrData objectForKey:key];
}

NSArray


NSArray* arrData = ...;
 [arrData objectAtIndex:1];

Loop

for (int i = 0; i < [arrData count]; i++) {
     [arrData objectAtIndex:i];
}

Besides these options you can also use enumerateKeysAndObjectsWithOptions. But I personaly dislike it cause it "feels" bad.

If you have an array of similar objects and you want all of them to perform the same selector you can also do this:

[[self.view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];

This will save you some lines of code and is very "readable".

Cheers

JayEs

Sunday, December 12, 2010

First Post

This is going to be a blog about dev and tech related topics.
The main topics regarding development will be:
  • Objective-C / Cocoa
  • PHP
  • Java / Android
 Like many developers when faceing a specific problem I often start googling for it to see how other people solved it. This Blog shall show code blogs I found usefull or highlight specific topics the community asks for. To help others out there trying to solve a task...