Ad

Our DNA is written in Swift
Jump

Category Archive for ‘Q&A’ rss

Adding Numbers to an Array

reembertoparada asks:

I have a loop from 1 to 30 and I want to create an NSArray with those values inside. Can you give me an idea on how to do this.

That’s an easy after-dinner exercise. First you need to take an NSMutableArray instead of an NSArray because regular objects without “mutable” in their class name cannot be changed. This is especially vital to know for arrays and dictionaries.

Read more

Adding Days to an NSDate

Nagarajan asks:

I just want to get a date which is some 50 or 60 days away from current date.

How do i get??

There are two methods to achieving this. One that is quick and (potentially) dirty. And one that is always safe.

Read more

How to Fix Code Signing Errors

Andreas asks:

With Device | Debug and Code Sign “iPhone Developer” I have no problems getting my app onto the device, but with all other configurations I get this strange error message in XCode Organizer.
Unexpected Error

That’s a weird error that most of us have encountered one time or the other. Here are my hints how to get it fixed.

Read more

Shorter Back Buttons

Today, on the train to the big city, I watched the seventh Standford iPhone Programming lecture and got an answer to a question I’ve been having for a long time.

Can I make the back button shorter in a UINavigationView? I like long titles, but it looks ugly on the back button!

The back button of a view that you pushed on the the navigation stack defaults to the previous view controller’s title. You want to make the title explanatory so a long one is good. But if you push another view controller onto the navigation stack you want the space to have an explanatory title on this one, or you need the space for something else.

Read more

Contacting the App Delegate

Remover asks:

How to send a message from a view controller to app delegate?

That’s a question that everybody asks who is trying to follow the model-view-controller paradigm. There is an easy way to access your app delegate from anywhere in your app.

Read more

Learn to Say No

This request of MKureth is so totally crazy that I just had to share it with you:

Hi, I am currently working 60+ hours a week on highly advanced interactive development which mainly consists of Flash (AS3), XML, JavaScript, PHP, and MySQL. I was asked to learn and develop a working iPhone application using the frameworks of Cocoa, Objective-C, and OpenGL within two weeks. Given my current work schedule and skill sets, how should I proceed with this request and deadline (of two weeks) keeping in mind that I have no prior experience with Mac development?

As impressive as your resumé sounds you lack a couple of essential skills.

Read more

The Best Way to Save Data

BebopSong asks:

Can anyone tell me the best way to create and store data on the iPhone so that the app can read the data but also write to it?

Having tried out all the possibilities that the iPhone platform holds in stock, here’s my opinion.

Read more

NSString Category for Compressing Whitespace

Anonymous users keep asking:

How do I remove whitespace characters from a string?

A quick way to do that is to first split the words in the string by whitespace characters and then join them back together without seperator. But there is a more elegant way to achieve this, that’s reusable at the same time: extend NSString by adding a category to compress whitespace to an arbitrary seperator.

Read more

OpenStreetMap in a UIWebView

Nicholas asks:

I’ve made an attempt recently to incorporate OpenStreetMap into my app. I’ve failed miserably. The result is a blank webpage. Any help/hints would be appreciated.

I immediately suspected that there was wrong with how he constructed the URL for the UIWebView, because I did run into a similar problem before.

Read more

Minimum/Maximum of Multiple Values

MadIvad asks:

Is there some sort of math function for the minimum of a set of values? I have searched the docs and not found one reference to math in iPhone OS2.2, and min only returns the like of ‘minimum’ for different control values. or for stating what the minimum of the integer or NSUInt class etc…

Does a function/class/anything exist that would simply return the lowest value of 2 or more values?

Boy, that was easy. There are compiler macros defined that work on any scalar datatype. MIN(a,b) and MAX(a,b). Note the case.

Read more