Thursday, April 4, 2013

Testing Definitions

Severity
Severity determines defect's effect on the application

Priority
Determines defect's urgency for repair

Defect

Tuesday, February 12, 2013

Categories vs SubClass

Prefer Categories for adding functionality to an existing class and also want to affect the behaviour of All instances
whereas SubClassing is better option for customization and if benaviour of only certain instance needs to change and retain the original method for others.

Wednesday, February 6, 2013

NSUserDefaults-Mutable method sent to immutable object

As the documentation for NSUserDefaults says: "Values returned from NSUserDefaults are immutable, even if you set a mutable object as the value." Whenever you want to change a collection you get from NSUserDefaults you have to get the imutable version, make a mutableCopy, modify that, and set it back again.

For E.g:


   NSMutableArray *placesT= nil;
   NSrray *tempArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"placesT"];

if (tempArray) {
    placeT = [tempArray mutableCopy];
} else {
    placesT=[[NSMutableArray alloc] init];
}

[placesT addObject: [NSString stringWithFormat:@"%@", tagF.text] ];

NSUserDefaults *tUD=[NSUserDefaults standardUserDefaults];
[tUD setObject:placesT forKey:@"placesT"];
[tUD synchronize];

Thursday, January 17, 2013

Copy vs MutableCopy


The difference between 'copy' and 'mutableCopy' can be simply understood with polymorphism in Object Oriented Programming concepts.


We will take the example of Array in objective-C. MutableArray is the extension of NSArray class. Therefore, all the methods available in NSArray is available in NSMutableArray, but the additional methods present in NSMutableArray is not known to NSArray class.

Now moving ahead, the copy method on an NSArray will return an object of type NSArray(The array that can not be modified). And mutableCopy method will return an object of mutable type (The array that can be modified).

Now, there can below cases :

Case 1:

    NSArray *arr1=[NSArray arrayWithObjects:@"A",@"B",@"C"nil];
    NSArray *arr2=[arr1 copy];

    NSLog(@"arr1:%@",[arr1 description]);
    NSLog(@"arr2:%@",[arr2 description]);

In this case an NSArray object is returned and is received in an NSArray object.
So, the array received can not be modified.

Therefore, we will not be able to use below statement
[arr2 insertObject:@"Z" atIndex:0];


Case 2:

    NSArray *arr1=[NSArray arrayWithObjects:@"A",@"B",@"C"nil];
    NSArray *arr2=[arr1 mutableCopy];

    NSLog(@"arr1:%@",[arr1 description]);
    NSLog(@"arr2:%@",[arr2 description]);

In this case an NSMutableArray object is returned and is received in an NSArray object.
Since the receiver object is of type NSArray, it doesn't know the methods present in NSMutableArray, arr2 will not be able to use any of the methods of NSMutableArray.
That is, the method mutableArray will make no sense in this scenario.

So, we will not be able to use below statement
[arr2 insertObject:@"Z" atIndex:0];

Case 3:

    NSArray *arr1=[NSArray arrayWithObjects:@"A",@"B",@"C"nil];
    NSMutableArray *arr2=[arr1 copy];

    NSLog(@"arr1:%@",[arr1 description]);
    NSLog(@"arr2:%@",[arr2 description]);

In this case an NSArray object is returned and is received in an NSMutableArray type object. The receiver arr2 is now pointing to an object address that is of type NSArray. However arr2 has the additional methods than NSArray, it will not be able to use those methods coz the pointed object NSArray does not know the additional methods present in arr2(NSMutableArray).

Hence, we will not be able to use below statement
[arr2 insertObject:@"Z" atIndex:0];


Case 4:

    NSArray *arr1=[NSArray arrayWithObjects:@"A",@"B",@"C"nil];
    NSMutableArray *arr2=[arr1 mutableCopy];

    NSLog(@"arr1:%@",[arr1 description]);
    NSLog(@"arr2:%@",[arr2 description]);
    [arr2 insertObject:@"Z" atIndex:0];

In this scenario, the receiver(arr2) of type NSMutableArray receives an object of type NSMutableArray. Therefore, the receiver knows the additional methods of NSMutableArray as well as the object that is being pointed by receiver(arr2).

And finally below statement will work like charm,
[arr2 insertObject:@"Z" atIndex:0];

Log before insertion will be:
arr1:(
    A,
    B,
    C
)
arr2:(
    A,
    B,
    C
)
And log after insertion will be:
arr1:(
    A,
    B,
    C
)
arr2:(
    Z,
    A,
    B,
    C
)



Hope above description helped you.
Refer:The link below clearly explains the difference between copy and MutableCopy
http://sarojsblog.blogspot.in/2011/07/difference-between-copy-and-mutablecopy.html

ELCPickerController

The need to pick multiple images from a photo Album in one go made me to look into ELCPickerController.It's similar to UIImagePickerController except that it allows us to select multiple images.
It has 2 Delegate method one will send us an array of dictionaries.Each dictionary for each image so the array contains info about multiple images.

Friday, January 11, 2013

NSDate Helper methods

1.To display time in relative time stamp use this method


-(NSString *)dateDiff:(NSString *)origDate {
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setFormatterBehavior:NSDateFormatterBehavior10_4];
    [df setDateFormat:@"EEE, dd MMM yy HH:mm:ss VVVV"];
    NSDate *convertedDate = [df dateFromString:origDate];
    [df release];
    NSDate *todayDate = [NSDate date];
    double ti = [convertedDate timeIntervalSinceDate:todayDate];
    ti = ti * -1;
    if(ti < 1) {
     return @"never";
    } else  if (ti < 60) {
     return @"less than a minute ago";
    } else if (ti < 3600) {
     int diff = round(ti / 60);
     return [NSString stringWithFormat:@"%d minutes ago", diff];
    } else if (ti < 86400) {
     int diff = round(ti / 60 / 60);
     return[NSString stringWithFormat:@"%d hours ago", diff];
    } else if (ti < 2629743) {
     int diff = round(ti / 60 / 60 / 24);
     return[NSString stringWithFormat:@"%d days ago", diff];
    } else {
     return @"never";
    } 
}

2.If NSDateFormatter returns nil then use the below method to fix 
NSDateFormatter *parser = [[NSDateFormatter alloc] init];
[parser setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];