Skip to content

Personalizing The Factory


Difference between Set (Swift ) and NSSet

One major difference I have observed between Set introduced as part of Swift and NSSet which is already available in Foundation framework is the way isSubSet method works in both.

NSSet does not bother the difference between a proper subset and a subset. But Set in Swift has method called

isStrictSubsetOf  in addition to isSubsetOf  which captures the scenario which Foundation fails to.

Swift Set

var set1 = Set(["r","a","m"])
var set2 = Set(["r","a","m"])

var bool = set1.isSubsetOf(set2) as Bool
var bool1 = set1.isStrictSubsetOf(set2) as Bool

 bool = set2.isStrictSubsetOf(set2) as Bool


Foundation NSSet 

NSSet *set1 = [NSSet setWithObjects:@"a", @"b", @"c", nil];

NSSet *set3 = [NSSet setWithObjects:@"a", @"b", @"c", nil];;

NSLog(@"isEqual :%d", [set1 isEqualToSet:set3]);

NSLog(@"isSubSet :%d", [set1 isSubsetOfSet:set1]);

For differences between Proper Subset and Subset

Warning :-Presenting view controllers on detached view controllers is discouraged

This log message I received when I was running my app  and it led to a strange UI glitch, where one of my  view in the application lost all of its subviews.


This error occurred once the modal view controller was dismissed.


I had legacy code from the days of iOS 4.0. The view which was losing its subviews is a View controlled  by a UIViewController. So this view controller was not added as a ChildViewController of the Parent Controller.


Added the viewcontroller responsible for this problem as a child of the parent controller and the problem was resolved

How to Extract the Images From Any App in the App Store

Objective C#


Recently I discovered how incredibly easy it to extract the original, full-resolution images (and other resource files like video, audio, .plist files) from any app in the App Store, without jailbreaking, and without special software. For iOS developers, this can give a fascinating look at the insides of an app. As always, be sure to do this for learning purposes only and respect all apps’ intellectual property.

View original post 214 more words

The Fallacy Of Android-First

The cost of Fragmentation is so high when compared to iOS and this will lead to user frustration and brand name gets tarnished

Sharing the iOS SDK, Xcode installers with other people

Each time a new version of iOS SDK , Xcode is available for update, we have to download a .dmg  file with size of 2.0+ GB and lot of time to get the update. So when many people want to share the dmg, instead of downloading the dmg from the appstore, it is better to download it once and share it with others.

The link where you get all these installers is:



Core data Fetch Request returning wrong number of records

I  am using Core data’s NSFetchRequest to extract all distinct values of a column from a Table. Sometimes I would need to extract all the items without any NSPredicate  and sometimes with the predicate.

So I started getting two weird problems when I  used the below code:

NSEntityDescription *entity = [NSEntityDescription  entityForName:@"EntityName" inManagedObjectContext:coreDataContext];

NSFetchRequest *request = [[NSFetchRequest alloc]init];

[request setEntity:entity];

[request setPredicate:predicate];

[request setResultType:NSDictionaryResultType];

[request setReturnsDistinctResults:YES];

[request setPropertiesToFetch:[NSArray arrayWithObject:propertyName] ];

// Execute the fetch.

NSError *error;

NSArray *objects = [coreDataContext executeFetchRequest:request error:&error];

The expected Result:

An array of the NSDictionary-ies with key being the name of the property which we are searching for and the value being the unique value of the property.

Problems I faced:

1. There was an extra record appearing in the result array with an empty key and a value. All other records will had the unique values . (This occurred when I use a single property condition check in NSPredicate)

2. The result always had only 1 record irrespective of the number of unique values.

I used the sqlite queries to check if what I am doing is correct.


I verified that whatever I was doing was correct.

Then I tried altering the values of NSPredicate string. Thats where the root cause was.

valid NSPredicate:

NSPredicate *predicate  =  [NSPredicate predicateWithFormat:@”prop1==%d AND prop2==%@”,value1,value2];

Invalid NSPredicate:

NSPredicate *predicate  =  [NSPredicate predicateWithFormat:@”prop1 == %d AND prop2 ==  %@”,value1,value2];

Not much difference between the two predicates right? Yes, except the spaces between property name and == operator and the value.

the device does not support this instrument

While testing for leaks in iOS device, I received this error.

the device does not support this instrument.

The problem I had was, I have not chosen the Provisioning Profile at all in the Xcode for this device. After selecting an appropriate profile, the problem did not occur.

Convert a xml file to plist

You can do it in two steps:

1. Convert xml to json. (use an online tool to do it. I used

2. Go in to the target folder location( where your have the  json file to be converted)  in terminal.Use plutil to convert json to plist.

plutil -convert xml1 blahblah.json -o blahblah.plist

Using blocks for different modes of TableView

Design Scenario

We have a single Home screen displaying information (in a UITableView)based on user’s preferences.   Lets say there are three modes the home screen can be accessed with.  Now based on each mode,  different information is displayed in cells with the layout of the UITableViewCell itself being  different on each mode. The approaches I have taken to solve this problem are

Option  1:

Use different UIViewController for different mode. This is a simple solution and does not create any further problem in terms of performance. (if  the readers find any problem with this approach please comment it. I will update the post after evaluating it)

Option 2: (The  solution which makes you think it is easy to do)

Use UIViewController’s itself the datasource and delegate of  UITableView to display different information  based on different mode by using Different UITableViewCells (obviously different layout)

Now the problem here is if there are (1+n) different modes , then this approach is a very bad approach because each time you compare in delegate and data source methods what mode the controller is which will affect the usability at least by a negligible amount.

Option 3:

In UIViewController’s viewDidLoad method, determine the mode of the application  and create a separate model controller (derived from NSObject and complying to UITableViewDataSource and/or UITableViewDelegate based on your requirements) for each mode set them as appropriate dataSource and delegate of the UITableView in your view controller.


Option 1 and Option 3 are better solution than Option 2 interms of performance.

Block based solution:

With blocks introduced in iOS 4.0 (nearly three years ago), our approach to solving the above problems can be made much better.

Additional Solution with Blocks:

(Assumption that we have only one section in UITableView)

Block based Solution  for Problem 1:

typedef   NSInteger (^NumberOfRowsInSection)(NSInteger section);

typedef id (^CellCreationForDifferentModes)(UITableView *tableView , NSIndexPath * indexPath);

@interface SPDifferntTypesController ()


NumberOfRowsInSection  numberOfRows;

CellCreationForDifferentModes cellcreation;


- (void)viewDidLoad


if (self.type == SPType1) {

__block SPDifferntTypesController *blocksafeSelf = self;

numberOfRows = ^()


return 10;


cellcreation =  ^id(UITableView *tableView , NSIndexPath * indexPath)  {

//Create cell and return it

//Type 1 cell




__block SPDifferntTypesController *blocksafeSelf = self;

numberOfRows = ^()


return 5;


cellcreation =  ^id(UITableView *tableView , NSIndexPath * indexPath)  {

//Create cell and return it

//Type 2 cell




#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section


return numberOfRows(section);


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath


return  cellcreation(tableView,indexPath);