iPhone Development

Just another iPhone Blog

longLongValue issue in NSDecimalNumber

Problem: A legacy module in current project involved JSON parsing where SBJSONParser was being used. While doing performance analysis, we found out that SBJSONParser was contributing to 50% to the load time of the module. The benchmarks done here ( https://github.com/bontoJR/iOS-JSON-Performance  )  convinced us to use NSJSONSerialization, a native JSON parse in iOS 5.0 and above. Things went smooth except with the change except for the below issue

 

We were using 64bit number to represent primary key.  NSJSonSerialization used NSDecimalNumber for representing numbers, while SBJSONParser used NSNumber to represent numbers. 

 

With NSDecimalNumber, a number returned from its description or stringValue method found to be different from the value returned by longLongValue  method implementation by NSDecimalNumber.

 

For eg: 3924849704573025603 = 3924849704573025792

 

The reason is well explained here  http://stackoverflow.com/a/12421451/623569

 

The problem is that an exact value of an NSDecimalValue is only representable as … anNSDecimalValue.

You can get an approximate 64 bits IEE754 value with method doubleValue. When you try to use longLongValue you effectively get the result of casting to a long long int the approximate IEE754 value.

 

Many of the modules in our project were using longLongValue, means that we had no choice to do a Find and Replace in the source as application using this module was out in market used by many clients and the value was stored in the database.

 

 

How do I make sure the longLongValue of NSDecimalNumber be consistent with its stringValue method?

 

Solution: 

Categories in our Objective-C comes to our rescue.

By creating a Category of NSDecimalNumber and re-implementing longLongValue. this new implementation will convert the number to string using stringValue and return number of type long long using longLongValue method. Since, NSString uses NSNumber to make the conversion, the final value returned by longLongValue is equal to value obtained through stringValue method in NSDecimalNumber.

 

@implementation NSDecimalNumber (unsignedLongLongBug)

- (long long)longLongValue

{

    return [[selfstringValue] longLongValue];

}

@end

 

A point to note here is that we are not interested in the correctness of the value in our case, rather we are trying to make the results consistent as I am only looking for the number to be unique and not using the result for any calculation. 

 

 

A word of CAUTION: Using a method in category to replace Primary class’s implementation may have unknown impact in case if there is a second category which implements the same method. In real word it depends on order in which the category is loaded and always the the method is replaced by the last category to be loaded.

 

 

Git – Basic Terminal Commands Checklist

I was observing a lot of traction from the developer community about the Git and Github and last year I got a chance to use the Git, majorly because of the woes we had using SVN ( subversion ) as our source control  in our team where most of the members are working remotely. I was amazed to see the power of Git but the learning curve was very steep, especially if you are a long time SVN user. I chose to use terminal commands to operate Git instead of a GUI tool so that it would help me know how Git operates behind the scenes which is masked by many GUI tools out in the space.

I started preparing an Appendix of commands of myself which I would use on a daily basis and most of my usage of commands are recorded in this list. Since, Its been close to year where I have made this checklist and updated as I found new usage scenarios, I thought i would share this back to community and to the newcomers who are entering into Git world, to make their Git transition smoother.

IMPORTANT NOTE:

  • I assume that the readers / users of this checklist  have the conceptual details on how who Git operates.
  • I always referred remote repository as origin ( as most of the time I used only single repository and git names it as ‘origin’ by default ).
  • I have most of the times tested these commands in Mac OS X 10.8, however I would assume you know why you are using these commands and I would not be responsible for any data loss resulting from usage of these commands.

I have organized the following commands based on the usage scenarios:

1. Basic Update and Commit 

   a. Check the status of git  

git status

   b. Adding Files

git add <filename>

OR

git add <regular expression>

    c. Commit – only updates the Local repository and does not push to the cloud

git commit -am “Commit Message”

git commit -m “Commit message” <filename> 

    d.  Update to remote repository

git push <remote name> <branch>

By Default <remote name> would be origin, if no branch is specified, then it will be pushed to master.

 

2. Remove from staging == remove from svn tracking

git rm -r –cached <file path>

 

3. Git Branch 

 a. Creating a branch

git branch <branch_name>

OR

git checkout -b  <branch_name>

 

b. List all branches

git branch 

c. List all branches in remote repository

git branch -r

OR

git fetch && git branch -r

 

d. Merging a branch

 

1. To commit and push all the changes made in this branch to remote

//Commit all the modified files


 git commit -am “<Commit message>”   

git push origin <branch name>

   

2. Switch to destination branch where u need to merge your changes. 

For eg. If you want to merge in Feature 1 in master branch, then switch to master by ‘git checkout master

 

git merge <branch_name>

git merge –no-ff <branch_name>

 

c. Deleting a branch in local repository

git branch -d <branch name>

 

d. Deleing a branch forcefully on local repository

git branch -D <branch_name>

e. Deleting a branch on remote repository

git push <remote> :<branch _name>

f. Download a branch from the repository 

 (sometimes you need to execute ‘git fetch’ command before executing this command )

git checkout -t origin/<branch-name> 

4. Ignore New Files or Never track

- Place .gitignorefile in Git root directory

- Add the file path or wilde cards for e.g.,  *.xcodeuserstate entry for example using vi editor or any text editor. You can add each file to be ignored in a new line

- save the .gitignore file

- this will take effect only to the new files. if you want to ignore an existing file. do a git rm –cached <filename> and follow the above steps.

Please let me know through comments in this blog if there are any faulty usage of these commands, so that I could rectify it.

I will try to update this post as and when I find some new commands. Please let me know if you find this useful.

Happy Coding :)

Why I like Blocks?

In my last post here , I wrote about the syntactical difference between the Blocks and the C Funtion pointers. In this post I share my first hand experience on Blocks and how it changed my programming style and thinking, especially if you are not from Java / Javascript world.

 

In simple terms, Blocks are tiny independent code blocks that could be executed on its own. How did Blocks saved me? Lets take below code snippet as an example:

 

[imageDownloader downloadHUGEImage: ^(UIImage* newImage){

    [self createThumbNailForImage:(UIImage * newImage)];

}]

 

v/s

 

[imageDownloader setDownloadDelegate: self ];

[imageDownloader downloadHUGEImage];

..

..

.

 

- (void)imageDownloader:(BBImageDownloader*)downloader didDownloadImage:(UIImage*)image

{

    [self createThumbNailForImage:(UIImage * newImage)];

}

 

Advantage #1: It added more readability to my code:

Everyone would know what we are exactly doing after downloading an image, where as with delegate pattern, one has to jump to definition of the delegate methods, which sometimes resides in multiple files, by then you would lose the trace of the initial method.

 

Advantage #2: Eliminates Delegate Pattern

The same reason as above, With Blocks, you will no more have to spend your time in retain cycle which is more common mistake made by programmer when using delegate pattern in Objective-C, (although blocks do produce retain cycles, but they are easy to detect   )

 

 

Advantage #3: Save more context info variables.

Lets take an example of usage of beginAnimation: method on UIView in Pre-Block Era.

int state_before_animation = 0

[UIView beginAnimations:@" " contextInfo:& state_before_animation]

 

..

 

..

 

- (void)animations:(NSString*)animation didFinish:(BOOL)finish contextInfo:(void*)contextInfo

{

    //do some\

int *state_before_animation = (int*)contextInfo

//change state depending upon state_before_animation

}

 

 

- During the execution time between start of animation  and completion of animation, we lose the scope of local variables that were available at the start. This made the necessity of carrying these variables in the form of contextInfo

 

- It increases the burden of maintaining the integrity of the contextInfo variable during this time, it travels between different modules and sometimes b/w the third party libraries. 

 

With blocks, it makes much more simpler to write:

 

int state_before_animation =0

[UIView animateWithDuration:0.9 beforeAnimation:^{

 

}

afterAnimation:^{

   //do something depending upon state_before_animation

}

];

 

 Isn’t it decreases your development time?

 

Happy Coding :)

UITableView Tricks – Part 2 – Infinite Scrolling

Last time I posted about the UITableView Tricks to lay the cells of the tablview in Circular fashion. It was well received by the community and thank you all for your feedback and compliments. 

I received many requests for making this circular list scroll infinitely as with UIPickerView, which means that the list repeats forever. It really makes sense just because the list itself is in circular fashion and user expect the content to repeat, without him/her having to scroll back to top.

I came across the 2011 WWDC video – Advanced Scrollview Techniques which provides the best feasible solution to support infinite scrolling. Many attempts have been made before to find a solution by having the height of the scrollview’s content size to a large number so that it takes days, if not AGES for a user to get to the end point. But it was never a complete solution.

 

I went a bit closer to the perfect solution and here it is. The goal here is to provide a generic solution to a UITableView while having the user/ developer to do minimum or ZERO changes. This lead me to create a subclass of UITableView, and named as BBTableView

 

By using BBTableView,  a developer has to do ZERO changes ( some minor changes for additional functionality, explained later ) to enable infinite scrolling. 

 

Behind the scenes:

 

 The core logic of this solution is

 

1. To increase the tableview content by a factor of 3, so that we make the 3 copies of the content laid one after another vertically. 

2. Whenever the top end of the scroll is reached, move the the scroll offset back to start of the 2nd copy

3. When the bottom end of the scroll is reached, we move the scroll offset back to the start of the 2nd copy minus the height of the tableview, so that we end up showing the same content as we are now.

Infinite Scrolling

This solution did bring an obstacle to my goal of making this component as a Drag-n-Drop component. i.e. Making 2 additional copies of rows provided by datasource also changes the index paths used in datasource or delegate methods that are propagated to the component user, a developer who would use this component.

This can be avoided by intercepting the delegate or datasource methods to morph the index paths exchanged between the UITableView and the its datasource or delegate methods.

Thanks Evadne Wu , for allowing me to use the interceptor component written by her.

Two  properties have been added to BBTableView,

a. contentAlignment

Allows the change the direction of the semi-circle. It supports two directions


ClockWiseScreen Shot 2012 12 07 at 9 25 33 PM

eBBTableViewContentAlignmentRight - Layouts the circle Clockwise

eBBTableViewContentAlignmentRight – Layouts the circle Anti-Clockwise

b. enableInfiniteScrolling

    set YES to enable infinite scrolling. NO to reset to default scrolling behavior of UITableView

 

As every software, this component too have its Cons:

1. Since the issue with Index Paths resolved by intercepting delegate / datasource methods, Any additions or modifications to UITableView datasource/ delegate methods involving index path, requires a change to counterpart datasource / delegate methods implemented in BBTableView. However, on a good note, this change includes only getting the morphed index path and calling appropriate method on the receiver of Datasource interceptor.

A  sample intercepted Datasource method would look like:

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [_dataSourceInterceptor.receiver tableView:tableView cellForRowAtIndexPath:MORPHED_INDEX_PATH(indexPath)];

}

 

Check the source code updated in github here https://github.com/bharath2020/UITableViewTricks

Happy Coding :)

Blocks Syntax and its Variants

This post is specifically to me. I am not sure why I am not able to remember this simple syntax of the passing blocks as parameter.

 

So here it is.. Its very similar to C function pointers

<return type> (* [<function pointer name>])( [parameter1, parameter2….])

The only difference is to replace * to ^.  <function pointer name> is name of the block, Lets call its as as <block name>.  if you are using this directly to pass a block as  a parameter to a method, then the <block name> is not needed.

 

For Example, You declare a method which accepts a block as a parameter like this:

-(void)performLongOperation:( void (^)(NSError *error, id result))completionBlock;


Variants of Creating and Defining a Block


a. Block definition as part of method invocation:

 

One would invoke the block within the performLongOperation method definition as:

NSError * error = nil;

id result = nil;

..

..

..

completionBlock(error, result );

The caller would look like:

  [self performLongOperation: ^(NSError *error, id result){

        //what you want to do after performLongOperation?

    }];

This is one of the way where the whole body of the block is written as part of method invocation.

 

 

b. Block as a variable OR a named Block:

 

If the above code snippet looks complicated (esp. if the callback is very lengthy) or if there is a need to separate the callback from the caller, then you can give a name to a block like this:

  void (^ myblock )(NSError *, id result)  = ^(NSError *error, id result){

        //what you want to do after performLongOperation?

    };

where myblock is the name of the block. The method invocation would look like:

    [self performLongOperation: myblock];


c. Block as a custom data type


In some cases, we might want to pass a different callback functions based on certain conditions and in order to do that we can create our own custom data type using typedef.

typedef void (^my_block_type)(NSError *, id );

and create a block variable of type my_block_type which accepts two parameters of type NSError and id and returns nothing.

my_block_type validate_long_operation_result = ^(NSError *error, id result){

        //validate result

    };

 

my_block_type divert_to_second_operation = ^(NSError *error, id result){

        //do second operation

    };

Caller would look like this:

[self performLongOperation: ( should_chose_second_operation ? divert_to_second_operation :  validate_long_operation_result)];

 

Click Me for More Info on Basics of Blocks


Happy Coding :)


WWDC: Steve Jobs v/s Tim Cook

The Wait is over, but the excitement is still there. Yes, Its about the WWDC 2012 and surely its may not be the best of 23 WWDC conferences, but it did not disappoint either. Am sure you can find a lot of info on it here at Engadget WWDC 2012 Live Blog.

 

So, We can never leave the habit of comparing stuff with others, because you the know the value of the product only when you have competition, Right?. So we are going to see in this post certain aspects between this WWDC 2012 and the previous ones run by the Apple’s past Show man – The Steve Jobs.

 

To make it simple, we will focus on following aspects: 

 

1. Secrecy:

 

Tim Cook did mention about doubling down the secrecy @ All Things D Conference, but still Apple could not prevent the features list being spilled out before Today’s WWDC 2012 event.

Here is the question. Did anyone knew about the First iPhone before the WWDC at that time? But on the other hand, Steve jobs was at its best in creating the Pirate teams, except in case of iPhone 4 leak in a bar. 

 

Having said that, the media right now has grown HUGE (with the arrival of Twitter and establishment of Facbeook) than what it was in 2007 and add to the fact that there is immense spotlight on what Apple is doing virtually each day. With that, we should say Tim Cook & Co. did a good job

 

2. Presentation:

 

Tactically, it looks like Tim Cook did not want to come up with his own style and make the show a huge disappointment, Instead he picked the best of the steve jobs slides and wrapped up in a neat show.

 

Check out this slide.

 Screen Shot 2012 06 11 at 10 04 11 PM

 

Add to that the opening of the Keynote with Siri. Starting the Keynote with the a Product or an Ad is not new. The Famous 1984 Keynote ( http://youtu.be/RcRQWGFJ5YY?t=3m8s ) where Steve jobs led Macintosh speak for the first time, and then the Famous Ad ( http://youtu.be/w6SXMtmUsX0?t=7s ) where the PC Guy asks developer to go on Off for a year, are few examples of its kind. 

 

But, If everyone else can copy Apple, then it is absolutely fine for Apple to copy Apple. What do you say?

 

3. WOW Factor

 

You just check back the Keynote video and you see there is that Steve Jobs WOW factor missing. There was some great stuff with retina display, Maps, Next Generation Macbook Pro hardware, and so on.

The WOW factor I am speaking is something like these

 

iPod Nano taken a Smallest Pocket showing its usage. 

 

 

They got a Best Macbook Pro, But there was no sense of excitement created around it. Or Let me say they did not exaggerate it. These are kind of additional things which without its existence may not cause harm on Product sales, but would definitely have a positive effect in its presence.

 

Here’s another piece of Job’s Salesmanship

 

Introducing Macbook Air kept within a US Post Envelope showing its thinness:

 

 

Comparing all the best in the industry is one of the key aspect of Steve Jobs Keynote. As said earlier, the product value is known only when it has a competition and Apple today missed the key thing to compare Macbook Pro with its Competitiors.

 

Another example, is that they have taken a dig at Window in the past, but this time with the whole new maps, they demonstrated without a word on Google. I wonder if steve could resisted to do that!!

 

But Having said this, there is no harm done as their products introduced today speaks for themselves.

 

4. The Naming:

 

Something has gone wrong with Tim Cook and Co in naming their products. They do the best products but could not come up with best names for it. The ‘The New iPad’ (see the second ‘the’ in my sentence, I hate it) is really awkward. Definitely makes it much more confusing when the next iPad comes out.

 

And the worse is they did not name or did they really name the Macbook Pro as “Macbook Book Pro with Retina Display’ ?

Even worser, they don’t have the name on the Physical Device. Atleast, I don’t see them on the one displayed in Ads.

 

Screen Shot 2012 06 11 at 10 55 01 PMPro name

 

This is such a delicate thing, it acts as an Advertisement and plays a role in word of mouth advertisements for Apple. I always get excited to spot a Apple product in Bollywood and other regional language movies adopted to show the richness of the Character and that moment we feel proud to see the Apple Logo and the name, in case only the display is shown.

 

 

Summary:

 

There are other minute things like the way Tim Cook slowed down his pace than compared to his iPhone 4S keynote, the humors created by Phil Schiller and Scott on Android, and all these things show that the effort is being made to make the Conference a success.

 

To complement Tim Cook, He has made One major improvement from his Previous iPhone 4S event where he did not stay on his statistics for too long.

 

Overall, A decent Job by Tim Cook and Co where they took no risk in experimenting new ideas in Keynote and were pretty happy in demonstrating the tested and successful methods of presentations. Having said, it is hard on them to expect a new stuff in such a short time, and the fact that Steve Jobs Legacy has created a Halo effect in our minds. In that regards, Its a Job Well Done.

 

In Simple words, Their amazing products drove the show for themselves.

 

I wish Tim Cook & Co, and Apple All the very best :)

 

 

 

UITableView Tricks

 

 

 

 

Recently we came across innovative UI controls like Path and Clear controls. I am pretty amazed to see a simple UITableView and its cells in iOS, can be tweaked to get a eye-catching effects as in Clear app.  After that there came a series of controls using UITableView, but this one from raw engineering was quiet nice.

 

After playing with it, I revisited the nuances of UITableView and came up with this simple UI Layoout which is our topic now. Take at look at this demo

 

 

You can find the Circle View Source in GitHub

 

I drew this sketch quickly.

 

 

IMG 4359

  

 

I laid down some rules before I started implementing.

 

1. I made clear that this control will not built ground up from scratch

2. Want to leverage the full power of Dequeue in UITableView 

3. Above two rules, means I should be concentrating only on how the content is laid out to present the data in different manner to the user and make it fun.

 

The main task that revolves around this control is how do we lay out the table cells. I used some basic trigonometry function which find out the point in circumference of the circle.

 

So the heart of this control resides in this method where on the while we find out the YPosition of each cell and adding yOffset of the Scrollview’s content offset. This means that the cell would move relatively as the tableview is scrolled.

 

The goal is to find out the X Position which is obtained by using Circle / Ellipse Equation

 

y = vertical_radius * sin ( angle )


x = horizontal_radius * cos (angle)

 

-(void)setupShapeFormationInVisibleCells

{

    NSArray *indexpaths = [mTableViewindexPathsForVisibleRows];

    float shift = ((int)mTableView.contentOffset.y % (int)mTableView.rowHeight);  

    int totalVisibleCells =[indexpaths count];

   

    float y = 0.0;

    float radius = mTableView.frame.size.height/2.0f;

    float xRadius = radius;

    

    for( NSUInteger index =0; index < totalVisibleCells; index++ )

    {

        BBCell *cell = (BBCell*)[mTableView cellForRowAtIndexPath:[ indexpaths objectAtIndex:index]];

        CGRect frame = cell.frame;

        //we get the yPoint on the circle of this Cell

        y = (radius-(index*mTableView.rowHeight) );//ideal yPoint if the scroll offset is zero

        y+=shift;//add the scroll offset

        

        

        //We can find the x Point by finding the Angle from the Ellipse Equation of finding y

        //i.e. Y= vertical_radius * sin(t )

        // t= asin(Y / vertical_radius) or asin = sin inverse

        float angle = asinf(y/(radius));

        

        //Apply Angle in X point of Ellipse equation

        //i.e. X = horizontal_radius * cos( t )

        //here horizontal_radius would be some percentage off the vertical radius.

        //percentage is defined by HORIZONTAL_RADIUS_RATIO

        //HORIZONTAL_RADIUS_RATIO of 1 is equal to circle

        float x = (floorf(xRadius*HORIZONTAL_RADIUS_RATIO)) * cosf(angle );

        x = x + HORIZONTAL_TRANSLATION;

        

        frame.origin.x = x ;

        if( !isnan(x))

        {

            cell.frame = frame;

        }

    }

}

 

 

Couple Macros found in source code which you could control”

  • HORIZONTAL_RADIUS_RATIO – defines the ratio between Vertiacl and horizontal radius. HORIZONTAL_RADIUS_RATIO of value 1 is equal to circle
  • HORIZONTAL_TRANSLATION – Helps translate the position of whole Circle / Ellipse i.e the position of the cells 

You can find the Circle View Source in GitHub

 

 

IMPORTANT UPDATE: 

 

A major improvement has been made to this project. Please read UITableView Tricks – Infinite Scrolling  to know about the new features and improvements.

 

 

——————————————————————————————-

UPDATE #1: 

This Post has been featured in 

 

 ——————————————————————————————–

UPDATE #2:

Have modified the source code to support the inverse form of the circle i.e the circle can be turned toward right as shown in figure by setting the CIRCLE_RIGHT_DIRECTION macro to 1

 

Screen Shot 2012 07 19 at 11 03 55 PM

———————————————————————————————- 

 

 

 

Hope you enjoyed this. Let me know your comments.

Happy Coding :)

Thoughts on iOS UDID

There is a lot of buzz with Apple’s rejection of apps accessing UDID API . Let us analyze it.

 

 

What is UDID?

 

UDID is the unique identifier to identify an iOS device uniquely. Apple had exposed an API to access this unique identifier from the start of iOS 2.0 SDK. This made interesting things possible and eventually became a critical API for some of the application’s core functionality. For example. Flurry Analytics, depend on this UDID for reporting number of devices an application is activated. Although, I cannot go through all the list of application using this API, let us do some Impact Analysis and possible problems and their solutions from this move by Apple.

 

When would you use the uniqueIdentifier?

 

I would typically use it in the context where I need to uniquely identify the device in a pool of iOS devices, where this info is send to a centralized place and is used for various purposes. Standalone applications more often does not need this info, unless they have integrated with third party SDK like Flurry, to support non-core features of an application, such as gathering statistics. Therefore, we would not keep this category of applications as these does not have major dependency on UDID.

 

 

What would you do with uniqueIdentifier with a pool of device?

 

Scenario 1:

 

“A scenario could be where the application could act as client and all the instances of the application across the devices are writing some data into the centralized place, could be a Mac or a Centralized Server. In this case the unique identifier would be able to identify the application instance uniquely to resolve the conflicts, say while writing the data to same location.”

 

Syncing

Fig: Scenario 1 showing Application installed in multiple iOS devices syncs with Mac / Server sharing and updating the data

Example: A Simple Notes application where notes are recorded in various iOS devices and then are synchronized with the Mac Application, where the Mac Application acting as a centralized unit.

 

Scenario 2:

 

“Another scenario would be to individually track the number of devices in which the application is activated which helps the sales people to pitch up their sales or we can find them in many of the third party ads which aid in gaining statistics of the application”

 

Example: Analytics SDK like Flurry, InMobi and so on.

 

While the first scenario helps the application in its core functionality, the second scenario is matter of statistics that helps drive the sales. However, accessing a unique identifier of a device without knowledge is a breach of privacy which i believe the motive behind apple deprecating this API.

 

Before digging deep, Let us look at the alternative solution from Apple?

 

Special Considerations:

 

Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.

 

Well, CFUUIDCreate does create the unique identifier, but will that be sufficient to identify the Device uniquely?? Wait, am I sounding wrong! Your read it right.

Although Apple recommend to create unique identifier and store it in defaults, it works fine as long as the app isn’t deleted and re-installed by the user. Since, doing that would delete the defaults database and upon re-installing a fresh unique identifier would be created which defeats our purpose.

 

Let us track back and see what exactly we need

“We need to find a way where an application would identify uniquely against its clone across multiple devices.”

The critical requirement here is not creating a unique identifier, but persisting it from the time application is installed on a device till literally the lifetime of the device and not the application. Uh!!

There are many solutions floating around like the one from crashlytics, where they achieve the persistence by storing the custom unique identifier in the UIPasteboard. However, there are couple of cons here

  • Apple does not guarantee that the Pasteboard data persists permanently across OS upgrades or reboot
  • Any other application can access this data or override them and one need to ensure that this would be in un-readable form for other that the application which created it.

 

My Solution (Intermediate):

The solution is to change the way we modelled our application behavior. For you to understand, let me divide the iOS era into two.

Pre-iCloud & Post-iCloud.

In Pre-iCloud we used to treat each iOS device as a separate one even though they are owned by ( literally under same apple id) single person. This means that an app in iPhone would have different state than the one in iPad, and probably a External Sync would be required to get them into single state.

In Post-iCloud era, as a developer, one should not distinguish between an application installed in two iOS device grouped under single Apple ID, which is strong point behind the Apple’s iCloud – “It Just Works”. i.e the iCloud make sure that all the data and state information would be consisted across the iOS devices grouped under single Apple ID.

With that differentiation, the solution would be:

“Create a unique identifier as suggested by the Apple and  store them in defaults as wells as in iCloud. Check NSUbiquitousKeyValueStore or using this short piece of library from Mugunth Kumar which I liked, for storing into iCloud. So Even if the App is deleted, the same ID would be retrieved back from iCloud, unless your iCloud is reset which accom”

NOTE: We could use a same approach for tracking the number of apps installed with the difference being the count would be number of users installed the application rather than the number of devices using it.

 

What are your thoughts on this?

Capturing Exceptions while debugging

This one is a simple but could be time-saving :)

Scenario: If you are debugging and caught with awkward situation where the application crashes with an exception, like NSInvalidArgumentException and so on, but never take you to the place in the code where the problem exists.

 

Solution:

Remember, This solution is for Xcode 4.2.1 for Lion.

1.  Select View->Navigators->Show Breakpoint Navigator

Screen Shot 2012 02 22 at 4 42 58 PM

2. At the Bottom-left cornet, Click the ‘+’ symbol and Select ‘Add Exception Breakpoint’ Menu

Screen Shot 2012 02 22 at 4 43 20 PM

3. In the popped-up window you may select [All | Objective-C | C++ ] options to select what type of Exception should the execution stop.

Screen Shot 2012 02 22 at 4 44 15 PM

 

4. Click Done.

Restart your debug process and you should see the line of code that is causing the hassle for you :)

 

Courtesy: Apple Developer Document.

 

 

An Idea for replacement of TweetLonger!

Hey Folks,

Just got this crazy idea which I would like to share.

I was just annoyed for the way we have to read the tweets with 140+ characters. With most of the twitter clients ( almost all ) it takes the user to a website to read the whole tweet which in the process is truncating the user experience of reading the tweets within the client and disconnecting the user from the twitter client.

With due respect for 140 characters limit twitter has placed, we could use below trick to solve this issue. This trick uses the in-reply-to feature of the twitter and the ability of most twitter clients to align the chain of tweets (tweets which have been originated as a reply of other tweet) in a linear fashion which helps read the broken tweets without any fuss.

 

Screen shot 2011-11-09 at 8.51.57 PM.png

Fig: A Snapshot of Linked tweets from Twitter for Mac Read the text in the image excluding the twitter handle (i.e. bharath2020) at the start of each tweet.

 

Screen shot 2011-11-09 at 9.10.31 PM.png

Fig: One more way of displaying linked tweets by Twitter Application for Mac

 

This trick could be deployed in all twitter clients with the user typing the whole tweet and twitter client will takes care of breaking the tweets and creating a link between them,

Let me know what do you think of this.

Follow

Get every new post delivered to your Inbox.

Join 28 other followers

%d bloggers like this: