A9628298AF2F97B5E073C680D9D5DC85 Apps King Technologies

Tuesday, 25 February 2014




json parsing using NSJSONSerialization (inbuilt method in objective c)


make a request and get response data then ----




NSData *responseData  = [request responseData];

NSError * error;
    
    NSMutableDictionary * json=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
    
   // NSLog(@"%@",json);
    
    NSArray * arrayTemp=[json valueForKey:@"categorylist"];
    for (int i = 0; i < [arrayTemp count]; i++)
    {
        NSMutableDictionary *dict =[[NSMutableDictionary alloc]initWithDictionary:[arrayTemp objectAtIndex:i]];
        [dict setObject:[NSNull null] forKey:@"categoryImage"];
        [arrMainCategory insertObject:dict atIndex:i];
    }




Parse your json by this way-----
NSURL * url=[NSURL URLWithString:@"http://s42sport.com/polarice/json/games.json"];

NSData * data=[NSData dataWithContentsOfURL:url];

NSError * error;

NSMutableDictionary * json=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];

NSLog(@"%@",json);

NSArray * array1=[json valueForKey:@"c"];

NSLog(@"%@",array1);


To print function name and values for  a method in class:

nslog(@" %@",__FUNCTION__);


Literal Syntax in Objective-C


Literal Syntax

Objective-C also offers a literal syntax for dictionary creation, like this:
    NSDictionary *dictionary = @{

                  @"anObject" : someObject,

               @"helloString" : @"Hello, World!",

               @"magicNumber" : @42,

                    @"aValue" : someValue

    };

Note that for dictionary literals, the key is specified before its object and is not nil-terminated.

Querying Dictionaries
Once you’ve created a dictionary, you can ask it for the object stored against a given key, like this:
    NSNumber *storedNumber = [dictionary objectForKey:@"magicNumber"];

If the object isn’t found, the objectForKey: method will return nil.
There’s also a subscript syntax alternative to using objectForKey:, which looks like this:
    NSNumber *storedNumber = dictionary[@"magicNumber"];


Mutability
If you need to add or remove objects from a dictionary after creation, you need to use theNSMutableDictionary subclass, like this:
    [dictionary setObject:@"another string" forKey:@"secondString"];

    [dictionary removeObjectForKey:@"anObject"];

Represent nil with NSNull
It’s not possible to add nil to the collection classes described in this section because nil in Objective-C means “no object.” If you need to represent “no object” in a collection, you can use the NSNull class:
    NSArray *array = @[ @"string", @42, [NSNull null] ];



NSNull is a singleton class, which means that the null method will always return the same instance. This means that you can check whether an object in an array is equal to the shared NSNull instance:
    for (id object in array) {

        if (object == [NSNull null]) {

            NSLog(@"Found a null object");

        }

    }



Execute Tasks in Background

Search bar customization in iOS





search bar change image inside of search bar (white by default)

UITextField *searchField;
    NSUInteger numViews = [searchBar_.subviews count];
    for(int i = 0; i < numViews; i++)
    {
        if([[searchBar_.subviews objectAtIndex:i] isKindOfClass:[UITextField class]])
        {                                                                              //conform?
            searchField = [searchBar_.subviews objectAtIndex:i];
        }
    }
    if(!(searchField == nil)) {
        searchField.textColor = [UIColor whiteColor];
        [searchField setBackground: [UIImage imageNamed:@"submit-button@2x.png"]];//just add here gray image which you display in quetion
        [searchField setBorderStyle:UITextBorderStyleNone];
    }




change search icon in search bar…

- (void)setSearchIconToFavicon
{
    // Really a UISearchBarTextField, but the header is private.
    UITextField *searchField = nil;
    for (UIView *subview in searchBar_.subviews) {
        if ([subview isKindOfClass:[UITextField class]]) {
            searchField = (UITextField *)subview;
            break;
        }
    }
    if (searchField) {
        UIImage *image = [UIImage imageNamed: @"icon.png"];
        UIImageView *iView = [[UIImageView alloc] initWithImage:image];
        searchField.leftView = iView;
      
    }

}

Links: Audio Player



There are many links for making audio player in iOS.


















imp slider and progressbar





backgrounding task