Ad

Our DNA is written in Swift
Jump

Category Archive for ‘Q&A’ rss

How to send image to remote server

Somebody asked on StackOverflow:

how to send image to Remote server from the below code last string is placed with image

NSString *reqString=[NSString stringWithFormat:@”http://projeceads.info/spir/productinfo/productadd/%@/%@/%@/%@/%@/%@/%@/%@”,ownerId,productNameTxt.text,QuantityTxt.text,sizeTxt.text,ageTxt.text,priceTxt.text,descriptionView.text,imgstr]; NSURL *reqUrl=[NSURL URLWithString:reqString]; NSURLConnection *connection=[[NSURLConnection alloc]initWithRequest:[NSURLRequest requestWithURL:reqUrl] delegate:self];
[connection start]; }

Now there are several things wrong with this question. This is the very first question this person asked on StackOverflow and he didn’t even set a proper user name yet. The code is not formatted as such, the English is bad and to most casual onlookers it is unclear what this question is about.

Still I felt an urge to give a good answer because often it is non-sensical questions like this that challenge our ability to parse the intent of the asking person and our knowledge of the subject matter. It is also such a situation where you can give an answer that exactly matches the question as well as a second answer that is a better way of achieving the intent.

Read more

Assorted Observations

While I am developing my first own Mac app I’ve been adding to this blog post whenever something was weird to me. Or simply different.

You can definitely see in many instances how some modus operandi on iOS has its roots on Mac, but Apple had to change things a bit around to accomodate the different UI paradigms on the mobile platform.

Read more

CoreLocation Background Update Messaging

Two years ago I put together revolutionary chart that detailed the flow of delegate messages when sending an app into background. This was even featured by Erica Sadun of TUAW because it for the first time visualized the whole process in a easy to understand way.

Based on this chart Carl Brown from PDAgent made an addendum to deal with the special case of background region updates and sent it to me. To my shame I have to admit that it was sitting at the bottom of my inbox for 4 months now and it is only now that in my effort to reach Inbox Zero I am dealing with this and putting it up here for your viewing pleasure.

Read more

Beware of NSString Optimizations

There are some scenarios where NSString acts as a class cluster internally to optimize handling of certain strings. One such case bit me today, and so I want to tell you about it.

Class clusters work such that you think you are always dealing with just instances of NSString, but in reality the runtime goes and chooses different subclasses for certain tasks. You might have already seen some effects of this behavior when debugging and the debugger actually showing you something other than NSString as the type of a variable.

Read more

ObjectiveSee Interview

ObjectiveSee is a web site dedicated to interviewing iOS developers. They use the format of a Q&A and they have several intriguing people’s up already: Justin Williams, Nathan Spindel, Keith Blount, Whitney Young, … oh and ME!

iOS 5 Breaking NSDateFormatter?

Robert Meraner asks:

“Do you have any idea why this code works in iOS 4.3, but no longer under iOS 5? Googling it seems to turn up some ideas, but no immediate explanation.”

This is the code Robert refers to:

NSString *currentElementValue = @"01.12.2011 09:35:13 CET";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd.MM.yyyy HH:mm:ss zzz"];
NSDate *date = [dateFormatter dateFromString:currentElementValue];

This got me confounded initially as well, but thanks to Cédric Luthi we got an official answer to this riddle: works as intended!

Read more

Bit Masks

Joseph Collins asks:

How do you decipher a bit mask from an argument which logically OR’d multiple values together? Enum uses bit shifting.

This question came to me while looking at UIView’s header file and wondering how Apple handles the animation options bitmask.

If you have several modes of something then usually you get by with an emum. But if you can combine several flags in s single value then you have to do this by means of bit masks. Let’s explore these today.

Read more

Coding Style

Dany asked:

I’m looking at your (nice) project NSAttributedString-Additions-for-HTML and I have some questions about your convention of writing code.
I really hope that you can reply to me, and maybe can be an idea for a future blog post (on naming conventions, and conventions in general for objective-c).

I adopted several styles I read about in the coding style guides by Google and Marcus Zarra, though I have to admit I only skimmed through these and picket a couple of things that made sense.

Though it is good practice to reflect on your style every once in a while to see if it still serves the purpose of making your code easier to maintain and read.

Read more

Podcasts for iOS Developers

I once dabbled a bit in podcasting myself with the Dr. Touch / Cocoanetics podcast, but I decided that I am not going to continue that on my own. I still like to TALK about it, if there’s somebody out there looking for a co-host …

Update: I resurrected the Cocoanetics Podcast! Subscribe to it on iTunes or add the RSS feed to your favorite podcasting app or listen to the shows right on this website.

Whenever I walk the dog, doing chores or “grounding myself” while gardening I like to listen when experts in our industry are discussing latest developments that impact my professional live as iOS developer.

So I asked on Twitter what your favorite related shows are and from the answers I made this list. And YES I checked it twice (several people were asking).

Read more

NSAttributedString+HTML Q&A

Over the past few months I have received questions about NSAttributedString+HTML and Rich Text Editing. Here are the Frequently Asked Questions.

I generally abbreviate NSAttributedString+HTML as NSAS+HTML. If your question or app is not in this list please let me know.

Read more