Tuesday, September 25, 2012

Force a block of code to only run on release / production

As in, I want to log a bunch of data, but only when I'm running the app on my computer (in Debug or Development mode). From the sounds of it, the preprocessor macro DEBUG is set to 1 automatically for Debug and Development mode so you don't actually have to do anything.


How can I add an #ifdef DEBUG to Xcode?

zoul answered:

In recent Xcode project templates there’s already a DEBUG=1 macro defined for the Debug build configuration (in the Preprocessor Macros section). You can test it using the #if preprocessor directive.

Also check out zoul's comment, he gives you all the info you need:
Ah yes, thanks, the whole build thing is getting… complicated :) I’ve edited the post. @nevan, take a look at Build Settings and filter for “preprocessor”. You should see a section called Preprocessor Macros, that’s where you should put a DEBUG=1 line next to the Debug sch—— configuration.

Basically

#ifdef DEBUG
 //put code here
#endif

if you want to avoid certain code running on the released version of your app

presentModalViewController deprecated in iOS 6

As a follow up to the last post, I also had presentModalViewController all over my app and it too has been deprecated. I quickly found the answer


A Lot of Functions are deprecated - iOs 6

PhilipCB answered:

[self presentModalViewController:pNewController animated:YES];
can be replaced by
[self presentViewController:pNewController animated:YES completion:nil];
which is really a great improvement because it gives us a completion block at the end. Thus, if you had any upkeep you needed to do after presenting the new view controller, you can assure it only happens once the view controller has successfully loaded.

Additionally dismissModalViewControllerAnimated has also been deprecated and replaced with a similar function to the presenting.

[self dismissViewControllerAnimated:controller completion:nil];






UITextAlignment Deprecated in iOS 6

I just switched my app over to point at iOS 6 and got hammered with 67 warnings, most being 'UITextAlignmentCenter' is deprecated: first deprecated in iOS 6.0' and thus, I needed to figure out what the new alignment class was. A quick search brought  me back to Stack Overflow and I found my answer. NSText! It has all the same alignment's that UIText did so a quick replacement of all my old code and I was happily on my way.


UILabel Align Text to center

Aravindhanarvi answered:

From iOS 6 and later UITextAlignment is deprecated. use NSTextAlignment
myLabel.textAlignment = NSTextAlignmentCenter;

Monday, September 24, 2012

First Post: A description of what I'm doing!

Starting up this blog for my use and yours. I've been doing iOS design for about 9 months now and I've found that www.stackoverflow.com is a great resource for finding answers to iOS / Objective C questions. I tend to just google a description of what problem i'm facing and view discussion results for Stack Overflow until I find something reasonably useful. More often than not, I've found the results I need, but sometimes I tend to forget exactly where I found them or what they actually were. Thus, I'm going to document any posts that I find useful here as quick reference, instead of having to sift through all the Stack Overflow posts again.

I'll start it off with a post I made a few months months back -


Get the extension of a file contained in an NSString

Dave Barry answered:

You're looking for [fileType pathExtension]