I’m still trying to learn Objective-C and have an app that downloads documents from a web server.
The documents are in ten, pre-defined folders and I have separate classes for each category
The way I’m accessing the files currently is, at the top of each .m file, I define the URL to the parent folder as a string, the subfolder as a separate string:
#define WEBHOST @"http://webserverURL/mainfolder"
#define FOLDER @"subfolderName"
then concatenate them:
NSString *pathString = [NSString stringWithFormat:@"%@%@", WEBHOST, FOLDER];
NSURL *documentsDirectoryURL = [NSURL URLWithString:pathString];
NSData *documentsHTMLData = [NSData dataWithContentsOfURL:documentsDirectoryURL];
I then parse the HTML with hpple and process as needed. I’m not sure if this is a particularly efficient technique and but it seems to do what I need.
However, it seems a bit messy and I imagine I’m missing some simpler or more efficient way of achieving this.
My question: is this a reasonable way of doing this or am I committing the typical newbie crime of making things more complicated and messy than they need to be?
Well, for one you could do the following:
And it should concatenate the webhost name to the folder name. Might save a line of code.