Posts Tagged ‘iOS’

XCode makes the life of iOS developers easier by providing the ability to debug code using break points, backtrace error logs and pin point the cause of errors when they occur. You can also let the compiler speak out the log message. If you haven’t played with it just go ahead and edit one of your break points to add an action when an error occurs.

But every now and then you will notice this beast “EXC_BAD_ACCESS”. As an iOS newbie you will hate this error and often I have seen pro devs struggle to find out the exact cause of this error. As this is one such error that will mostly throw you to your main.m file and you can’t find what exactly is causing this crash.

One thing I have learnt over last few years and that has helped me to debug an error faster is – “An error is what the error says”.

So before posting your ugly error message on stackoverflow or before even hitting google, stop for a while and look carefully what the error message tells. So let’s say I get this error on my tableViewController, or scrollViewController then before getting into what is wrong in my so and so view controllers, I would probably look first into what does “EXC_BAD_ACCESS” mean if I don’t know about it. Apple’s error messages are verbose and self explanatory. Hence, as one can clearly make out from the description “EXC_BAD_ACESS” means you are doing bad access or in other words you are accessing something that you shouldn’t.

Talking more in Obj-C terms – a message was sent to an object that doesn’t exist or that doesn’t understads the message. Hence, bad access.

You will get EXC_BAD_ACCESS error mostly in the following scenarios:

  1. You are trying to access an object that is not initialized.
  2. You are trying to access an object that no longer exists. Either it’s being released or it’s nil. In ARC mode, make sure you take ownership of the object that you want to use.
  3. You are passing an message to an object that the object doesn’t understand. It can also happen for bad typecast. Like the lines below where I am trying to access an int with %@ in stead of %d.
int myAwesomeInt = 9;
NSLog(@"%@", myAwesomeInt);

How to debug:

Identify what you did that caused the crash. Did it crash while view of a particular view controller didLoad or in a delegate method or on a particular action. That will often help to find the object that is casuing the error.

  • Most of the time “NSZombies” can help to identify the dead object. You can enable NSZombies by editing your scheme Product -> Edit Scheme -> Diagnostics.
  • If you still don’t find the root cause then always go backwards from child view controller to parent view controller to see what object needs to be retained or what message needs to be passed properly.
  • Look into Static Analyzer and Instruments for advanced debugging. 

6 months ago Me, Michael and Mugunth re-started the iOS Developer meetup group in Singapore and iOS Dev Scout was born. We started this community with a dream that this will help iOS developers in Singapore collaborate with each other, share knowledge & passion and build some kick-ass iOS apps together. So we meet for monthly meet-ups where speakers talk about great iOS technologies and showcase their cool apps. We also occasionally meet for longer coffee break sessions where we hack together on various apps.

Few months ago, Peter Kim (one of our meetup speakers) suggested to have an iOS Hackathon. The organizers liked it, the members were excited about the idea and tech companies and government organizations in Singapore stepped forward to support it. Many thanks to our sponsors iDA, Plug-In@BLK71, BuUuk, ELC, Quantum Inventions, Cloudy Rec, BubbleMotion, Viki for supporting us in organizing the 1st iOS centric Hackathon in Singapore. The local tech media communiy were very supportive as well. E27 and SGEntrepreneurs helped us in promoting the event. So 75 participants registered for the event. Chinmay helped us in live streaming the event so that people who couldn’t join could still catch the glimpse of this event live.

The day started with few tutorials on iOS, Objective-C, User Experience and API Integration. After a great keynote from Sayanee; Michael and Nav talked during the 1st half of the tutorial sessions. Me and Sithu shared more knowledge post lunch. About 16 ideas were being pitched. With plenty of Red Bull and Caffeine close to 35 people participants survived the night fighting with NSZombies. On demo day 13 apps were being demonstrated. Mentors from Founder Institute and local tech community provided feedback to the participants. We organizers applauded their work and rewarded 8 teams with Amazon gift vouchers who showcased great passion in building those awesome apps.

I was personally helping the participants to get started with iOS and Objective-C. It was great fun to see them learning really fast. Around 4 AM I started building a small proof of concept app for a friend of mine. And in couple of hours I was ready with the basic version of an iOS app for Learnemy. Elisha is a good friend of mine and hope she can make a good use of the app to showcase her product.

Out of those 13 apps my favorites are Alan’s Shadow and Thumbatar. We were happy to have newbies and students in the event as well who leaned Objective-C and iOS really fast and showcased some application on the same day. We hope to continue same in future to encourage and inspire iOS developers in building great apps and make Singapore a fun place to live for all the Hackers.

Join our Facebook group to get updated about our upcoming events and find our more about what iOS developers in Singaproe are hacking on.

  
So much talk about inclusion of Near Field Communication with iPhone 5. We can never know whether it’s going to be supported soon or not.

Few months back Apple filed a patent that reveled about their upcoming product called iWallet. This makes other similar initiatives by other providers or vendors look naive. This will arguably change the way mobile payments are being done today and definitely the one that will rule the world as mentioned in the article below.

The creative engineers at Apple have given enough thought to iWallet to make it work both in the scenarios of making transaction in person or remotely. This leads to another revolutionary steps that might replace credit cards, debit cards, gift card completely!

In stead of traditional One Time Password (OTP) that is being sent to a registered mobile device or a security token being used by an external devices; Apple is probably going to use an Application that’s running on iPhone / iPad / or on Mac to validate the transaction is authorized. A simplest thing I can think of is to validate authorization by iTunes password.

More over card holder can enable/ disable automatic authorization for certain merchants, below certain value and flag certain transactions as unauthorized that will immediately notify issuing bank or credit card association. The cardholder-not-present authorization functionality may also be combined with a distinctive gesture for example drawing a character or reverse swiping certain control.

From the screens below it’s clear that third party applications can be enabled for “MobilePay” to use the features of iWallet.

Reference Link: http://www.patentlyapple.com/patently-apple/2012/03/part-2-apples-iwallet-the-one-that-will-rule-the-world.html

I would sound naive if I will try to emphasize on how important testing is for building a high quality application. Be it a consumer mobile or web app or large scale enterprise application. I have been playing with iOS ever since the first SDK was released. And hence, worked with so many customers, clients, enterprises (starting from startups to fortune 500 companies).

And I think about 80% of those customers or clients prefer to do their testing manually and track the test results in excel or Bugzilla which is always time-consuming and requires a significant amount of man-hours every time we want to do a proper testing. iOS apps now supports automated Unit testing by default. But Unit testing only ensures that an unit of your code works properly and doesn’t guarantee the application will run properly under all circumstances.

Cedar is a BDD-style testing tool for Objective-C similar to rspec in Ruby. The documentation available online is bit old and doesn’t really work with iOS5. Hence, I would jot down few quick steps on how to use this tool.

1. Download the framework from GitHub: https://github.com/pivotal/cedar

2. Build Cedar-iOS static framework. You might want to change the default “Derived Data” directory path from its default location to the your project directory. So that you won’t have to look up in the archive of your application folder to find the static library.

3. Add these flags under “Other Linker Flags” in your build settings. -ObjC, -all_load, -lstdc++

4. Add Cedar-iOS static framework to your project.

5. Comment out the default codes on main.m and add the below lines which will launch CedarAppDelegate in stead of your application AppDelegate. Another way you can do this is to select UnitTest while creating your project and modify the main.m under the test directory. So whenever you will test the application it will launch Cedar.

#import <UIKit/UIKit.h>
#import <Cedar-iOS/Cedar-iOS.h>

int main(int argc, char *argv[])
{
	@autoreleasepool {
		return UIApplicationMain(argc, argv, nil, @"CedarApplicationDelegate");
	}
}

6. Create a new (c++) file called AdditionSpec.mm and you can write your test specs on this file. You can use matchers, mocks and stubs. For these things you can refer to the GitHub project.

#import "SpecHelper.h"
using namespace Cedar::Matchers;

SPEC_BEGIN(AdditionSpec)

describe(@"BehaviorSpec"), ^{
	it(@"addition should work properly"), ^{
			1+2 should equal(3);
	});
});

SPEC_END

7. Build and Run. It will display all the test results in a table view.

Let me know if you face any issues in building or running it. Happy Testing. 😉

# Omni Omnigraffle + iOS Stencil (Paid): http://www.omnigroup.com/products/omnigraffle/

Get Stencils from: http://graffletopia.com/

# Sketch-kit Keynote Template: (Free) http://www.extrathought.com/sketchkit/

# Photoshop PSD Files (Free)

iPhone PSD: http://www.teehanlax.com/blog/iphone-gui-psd-v4/
iPad PSD: http://www.teehanlax.com/blog/ipad-gui-psd/

Other Options (Around 21 Different Tools): http://goo.gl/SwU2b

Summary: Use the tool you are most comfortable with. For example if you are familiar with Keynote then use Sketch-kit or other keynote templates. I personally prefer OmniGraffle. Best way to judge is: check the sample screens or video of these tools and choose the one you like the most. 🙂

I took this initiative a month ago to help students, developers or start-up founders to get started with iOS Development. I closed the registration in a day with 35 interested participants. Many people, asked me why I haven’t kept any registration fee for these sessions. The idea is very simple – I have learnt so much from open source community – Unix, Php, JavaScript, Ruby on Rails, and iOS. Although iOS is not exactly open source but I still like the idea of Apple of bringing an app development SDK and making it open for other developers to put their apps on iOS Devices. The idea itself showed ways to a lot of people. And as I have learnt so much from this community, I want to give something back to the community. It’s more of a passion for me than a business. In one way, you can say I am helping my friends than helping someone I don’t know. And I wouldn’t ask money to a friend for my help. 🙂

Yesterday was the first session, and it was almost a full house At HackerSpaceSG. Thanks to Jason Ong for helping me to organize the event at HackerSpace. Together with all the awesome participants we explored and revealed XCode basics and Objetive-C syntax through a little program called “SaveThePrincess”. At the end of the session, I got some honest feedbacks. Where most of them said it was helpful, some couldn’t follow. Mostly people who couldn’t follow are from non-programming background. So I thought what I could do better that will help those set of people. My approach of this tutorial was to start with something basic and build components on top of it, which although assumes participants have basic programming knowledge.

Then Jason and few others suggested, we could reverse the approach. For example: show everyone, what’s the end product and then build individual components that’s required for the actual product. I am still looking for an interesting way to do it. But for sure – I decided I will show an application in next class before starting the tutorial. That might be fun for all the folks who wants to save our little princess. If you have any suggestions feel free to drop few lines here.

The materials of my first class can be downloaded from BoxDotNet. Our friend Calvin has explained more about the session on his blog. 

Ever since I installed iOS5 Beta firmware, I was curious to try out iCloud. It has so many amazing features like new notifications, over the air print for map, camera grid, better photo editing options to name few. Everything else was working except iCloud. Every time I tried it used to say “Your Apple ID is correct but the device is not registered/eligible for iCloud”. I thought may be it has something to do with the hardware.

Earlier today my friend told me that iCloud beta is released, and curiously I tried again and it worked and worked like magic.

For those who are listening first time about iCloud, this is a content integration platform which integrates all your contents and makes it available on all your apple devices like iPhone, iPad, iPod Touch and Mac. Everything happens over the air (wirelessly). Not only that, it makes all the app purchases available to all your devices. Apart from synchronizing it takes a back up of all the data (currently up to 5MB) and make it available on cloud. So if your device gets crashed, you don’t loose the data ever.

In this beta release it has got the following features:

  • Mail : Synchronizes and takes backup of mails in your inbox and makes it available on other devices
  • Contacts : Synchronizes and backs up your contacts
  • Calendar : Synchronizes and take backup of your Calendar Events
  • Find my iPhone: Locate your device, send message, lock and wipe data
  • iWork: Office suite, backs up all documents, presentations

The first look is amazing with future scope to support photo, music, app, video synchronization. Won’t be surprised if they plan to store the snapshot of the system like how they do it on time machine.