Tuesday 30 April 2013

What is NSAttributedString ?

NSAttributedString is like a  NSString, expet every single character has dictionary of attributes. These attributes are things Like font, colour, underline, and etc.


How to get the attributes:
You can ask an NSAttributedString all about the attributes at a given location in the string.
- (NSDictinary  *)attributesAtIndex : (NSUInteger) index
                                   effectiveRange : (NSRangePointer) range;


Remember NSAttributedString is not an NSString, it does not inherits from NSString. So, you can not use NSString methods on it. However if you need to use NSString method, you must first turn NSAttributedString to NSString then use the method.
written by: infinitywebseo  

What is UIColor?

UIColor is a subclass of UIKit. Its an object which represent color. You can create it based on RGB or HSB and even patterns (UIImage).

Colors can also have alpha (UIColor *color = [otherColor colorWithAlphaComponent: 0.3]).

A handful of "standard" colors have class methods (e.g. [UIColor greenColor]).

written by: infinitywebseo  

What is NSRange?

NSRange is a C Struct,  it used to specify sub-ranges inside strings and arrays.

typedef struct {

  NSUInteger  location;
  NSUInteger lenght;

} NSRange;

Important location value is "NSNotFound".

NSString *myString = @"Hi Every One!" ;
NSString *search = @"Hello";

NSRange range = [greeting rangeOfString:search];

if (range.location == NSNotFound) {

// could not find search in myString

}

written by: infinitywebseo  

libxml2 vs NSxmlParser

Libxml2 is c base and NSxmlParser is a real cocoa class. Libxml2 is always faster than NSxmlParser in terms of performance. 

If performance is an is an issue, you should definitely use libxml2, but if you are only prosessing a small amount of data NSxmlParser is a better solution. NSxmlparser it ismuch easier to implement and understand.

written by: infinitywebseo  


What is NSDictionary?

If you are parsing xml data on your iOS program, please keep in mind that the code is slightly different when read xml file local from when you read it from a server.


Parsing Local XML file: ( xmlparser.m )


-(id) loadXMLByURL:(NSString *)urlString
{
   
   
    NSData *xmlData = [NSData dataWithContentsOfFile:urlString];
    NSXMLParser  *parser = [[NSXMLParser alloc] initWithData:xmlData];


    parser.delegate = self;
    [parser parse];
    return self;
   
}


Parsing  XML file from Server: ( xmlparser.m )


-(id) loadXMLByURL:(NSString *)urlString
{    
   
    NSData *xmlData = [NSData dataWithContentsOfFile:urlString];
    NSXMLParser  *parser = [[NSXMLParser alloc] initWithData:xmlData];


   NSURL *url = [NSURL URLWithString:urlString];
    NSXMLParser parser = [[NSXMLParser alloc]initWithContentsOfURL: url];


    parser.delegate = self;
    [parser parse];
    return self;
   
}


If you have any Questions please comment.


written by: infinitywebseo

(id) loadXMLByURL Method (local xml, xml on server)

If you are parsing xml data on your iOS program, please keep in mind that the code is slightly different when read xml file local from when you read it from a server.


Parsing Local XML file: ( xmlparser.m )


-(id) loadXMLByURL:(NSString *)urlString
{
   
   
    NSData *xmlData = [NSData dataWithContentsOfFile:urlString];
    NSXMLParser  *parser = [[NSXMLParser alloc] initWithData:xmlData];


    parser.delegate = self;
    [parser parse];
    return self;
   
}


Parsing  XML file from Server: ( xmlparser.m )


-(id) loadXMLByURL:(NSString *)urlString
{    
   
    NSData *xmlData = [NSData dataWithContentsOfFile:urlString];
    NSXMLParser  *parser = [[NSXMLParser alloc] initWithData:xmlData];


   NSURL *url = [NSURL URLWithString:urlString];
    NSXMLParser parser = [[NSXMLParser alloc]initWithContentsOfURL: url];


    parser.delegate = self;
    [parser parse];
    return self;
   
}


If you have any Questions please comment.


written by: infinitywebseo

What is NSUserDefaults? (iOS)

Grand Central Dispatch (GCD) is a C API.  The basic idea is that you have queues of operations, which are specified using blocks. The blocks in the queue run in another thread except main thread.

There are two types of queues.  Serial Queues and Concurrent Queues
In serial queues blocks are executed in order. (one by one)

When do we use Multi-threading:

Accessing the network
Big calculation, hugs loines of code


Creating and releasing queues:
dispatch_queue_t dishpatch_queue_create(const char *label, NULL); // Null means serial queue

Putting blocks in the queue:
typedef void (^dispatch_block_t)(void);
void dispatch_async(dispatch_queue_t queue, dispatch_block_t block); //it puts the block in the queue then returns to main thread immediately

void dispatch_sync(dispatch_queue_t queue, dispatch_block_t block);  // puts the block in the queue and waits until the block finally gets to run to compelition and get backs to current thread

Getting the current or main queue
dispatch_queue_t dispatch_get_current_queue();
dispatch_queue_t dispatch_get_main_queue();


written by: infinitywebseo