Debugging EXC_BAD_ACCESS

This article is from http://www.cnblogs.com/junz/archive/2010/05/23/1742118.html , useful for debugging the annoying EXC_BAD_ACCESS exception.


You have to accept the fact that sooner or later you will need to debug an EXC_BAD_ACCESS problem and most probably won’t be easy to.

This article however is about how to make the process easier, in some cases easy as a piece of cake.

What does EXC_BAD_ACCESS mean?

EXC_BAD_ACCESS means that message was sent to a point in the memory where there’s no instance of a class to execute it. Thus “bad access”

When EXC_BAD_ACCESS happen?

You will get EXC_BAD_ACCESS in 3 cases:

  1. An object is not initialized
  2. An object is already released
  3. Something else that is not very likely to happen

That’s already a good starting point. Start using the debugger, if you recently added a new object to the class you’re working on, put a breakpoint at the line before the freshly added object is used for the first time and check the values in the debugger.

What’s happening most though is that you will be sending a message to an overreleased object – i.e. object that is gone from the call stack. In this cases everything (and indeed everything) you will get in the console will be just :

EXC_BAD_ACCESS.

This is because the object is gone, there is no information what class was it, or what source file or anything else. That’s really tough to debug with NSLog … NSLog is helpful, but you need to put 1,000 NSLogs around to fetch where is the problem.

Enabling NSZombies

The solution to overreleased objects are the zombies. When this feature is enabled, a dummy object (a zombie) is kept on the place of every released object, thus allowing to debug objects which were released already. Very easy to enable:

  1. Double click your executable in the “Executables” in XCode
  2. Open “Arguments” tab
  3. In “Variables to be set in the environment” (that’s the list at the bottom, be careful which one you edit) click the “+” button and for name of the variable enter “NSZombieEnabled” and for value “YES”

Voila!

Now instead of wondering what’s going on and which exact object produced the problem, you’ll see exactly which class is the trouble maker, and you’ll debug it quite fast.

Beware the zombies though

Just a reminder not to leave the zombies enabled, when you submit your app to the App store. Also, it’s a good practice to disable them if you don’t really need them.

All the sizes of iOS app icons

  1. 57 px, iPhone – good ol’ classic.
  2. 72 px, iPad
  3. 114 px, iPhone 4 – make sure your icon shines on the Retina Display.
  4. 512 px, iTunes – Used in iTunes and in the App Store, where it’s sized down to 175 px. Sadly, you can’t provide the 175 px version directly.
  5. 29 px, iPhone Settings/Spotlight, iPad Settings – used in these table views. Minor, but still important!
  6. 48 px, iPad Spotlight – yup, the iPad uses a different size for Spotlight and Settings. This size is controversial! Apple’s docs actually say the icon is 50 px, but then there’s this note: The final visual size of this icon is 48 x 48 pixels. iPhone OS trims 1 pixel from each side of your artwork and adds a drop shadow. Be sure to take this into account as you design your icon. How weird!
  7. 58 px, iPhone 4 Settings/Spotlight – that’s right, you have to make both 57 and 58 px versions of your icon – d’oh! Good luck aligning this if there’s a line running down the middle of the icon.
  8. 64 px document icon – who knew: iOS apps can provide document icons. It’s unclear how these will be used – they don’t do much currently – but it’s not a bad idea to start planning now.
  9. 320 px document icon – why not 256, darn it? :)
  10. Let’s say Apple comes out with a high-ppi iPad. That will mean at least 2 new sizes – maybe 144 px and 96 px.

From:  All the sizes of iOS app icons (Neven Mrgan’s Tumbl)

iPageRank Released

iPageRank is a handy tool for checking website Google PageRank on your iPhone/iPod Touch, anytime and anywhere.

iPageRank home page: https://langui.net/ipagerank/

iPageRank is available on iTunes App Store for free:

https://itunes.apple.com/us/app/ipagerank-pagerank-checker/id433671401?mt=8

How to “add existing frameworks” in XCode 4

Here is the step by step instructions:

  1. In the project navigator, select your project
  2. Select your target
  3. Select the ‘Build Phases’ tab
  4. Open ‘Link Binaries With Libraries’ expander
  5. Click the ‘+’ button
  6. Select your framework
  7. (optional) Drag and drop the added framework to the ‘Frameworks’ group

Original: https://stackoverflow.com/questions/3352664/how-to-add-existing-frameworks-in-xcode-4

cannot decode object of class (MKMapView)

Problem:

*** Terminating app due to uncaught exception ‘NSInvalidUnarchiveOperationException’, reason: ‘*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (MKMapView)’

Solution:

add the “MapKit.framework” library.

How to enable “swipe to delete” for UITableViewCell

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
// No editing style if not editing or the index path is nil.
if (self.editing == NO || !indexPath) return UITableViewCellEditingStyleDelete;
}

Server certificate verification failed

Got the following issue when trying to commit changes to SVN server:

svn: OPTIONS of ‘https://langui@langui.net/svn/MyProject/trunk/src’: Server certificate verification failed: certificate issued for a different hostname, issuer is not trusted (https://langui.net)

I’m using svnX, and it seems there is no way to get around this issue. I searched the web but found no solution.

Finally, I tried to update the svn working copy in terminal:

$ svn up

Error validating server certificate for ‘https://langui.net:443’:

– The certificate is not issued by a trusted authority. Use the

fingerprint to validate the certificate manually!

– The certificate hostname does not match.

Certificate information:

– Hostname: langui-server

– Valid: from Wed, 20 Apr 2011 15:08:48 GMT until Thu, 19 Apr 2012 15:08:48 GMT

– Issuer: langui.net

– Fingerprint: e6:52:b9:b6:f2:35:68:6c:cd:93:ef:b2:f3:15:02:dd:85:2b:1f:28

(R)eject, accept (t)emporarily or accept (p)ermanently? p

At revision 49.

Then try agin with svnX, it works!

Xcode warning: No provisioned iOS devices are available

I got this warning when trying to deploy my App into my iPhone 4: “No provisioned iOS devices are available. Connect an iOS device or choose an iOS simulator as the destination.”

After some googling I found the answer: the default target was set to 4.3 but my iPhone iOS version is 4.2.

I edited the target and set “Base SDK” to “iOS 3.2”, then everything is ok.

Seems it’s time to update my iPhone now.

Why “shouldAutorotateToInterfaceOrientation” doesn’t Work

The following is from Apple’s Technical Q&A:

  • All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set.
  • Overriding the -(id)init: or -(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle method without calling super. For the object to be initialized properly, you must call super on any init or initWithNibName method you are overriding for your view controllers.

For more detail please see:

Why won’t my UIViewController rotate with the device?

How to make iPhone app icon without borders

Open up the project in Xcode, open the Info.plist file, add a new row and choose “Icon already includes gloss and bevel effects” and checkmark it (set to true).

The original solutions can be found here:

http://forums.macrumors.com/showthread.php?t=747874