• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Can you provide some code advice for a newbie please?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Can you provide some code advice for a newbie please?


  • Subject: Can you provide some code advice for a newbie please?
  • From: Paul Harvey <email@hidden>
  • Date: Tue, 12 Jul 2005 09:48:06 +0100

On my quest to conquer Cocoa (!), I'm hoping for a quick pointer. I'm coming from a knowledge of C and PHP and RealBasic, and I'm beginning to understand the syntax of Obj-C, but I seem to be struggling with some basic things!

As an example, I want to enumerate through a chosen directory and get the name of all the directories found there (not a deep search, just that top level). Then I want to populate a NSPopupButton with the directory names.

I've got it working, after extensive searching of the documentation and some web searching, it's rewarding when it finally works!. The only problem is, it seems overly complex to me, having used other languages. I'm calling so many things that each call something else, just to get to the correct directory, etc.

My question: could some experienced coders look over this and offer me some advice please. Is this over the top for a piece of code doing this simple job? Could it be done much more succinctly?


Here's an example of the mess I seem to find myself in!

The NSpopupButton is called brfTranslation.


NSString *aTranslation,*appPath,*booksPath;
NSArray *availableTranslations;
NSFileManager *fileManager = [NSFileManager defaultManager];
appPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
booksPath = [appPath stringByAppendingString:@"/books/"];
availableTranslations = [fileManager directoryContentsAtPath:booksPath];


    NSEnumerator *en2 = [availableTranslations objectEnumerator];

// Setup the available Translations from those in the folder -------
while(aTranslation = [en2 nextObject]) {
if( ! [aTranslation characterAtIndex:0]==@".")
[brfTranslation addItemWithTitle:aTranslation];
}



One last question. The line '' isn't working properly. In fact not at all! I want to check whether the item found in the directory has a . as the first character and skip if it does. Is there a fileManager method for this? And how should I do it if I was using basic string slicing/character comparing methods?


Thanks for your help everybody.



--
Paul Harvey

Lead Programmer
email@hidden

Hiddenfield Software
"Creating useful software for Mac OS X"
www.hiddenfield.com


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Can you provide some code advice for a newbie please?
      • From: m <email@hidden>
  • Prev by Date: Re: Apple system icons: guidelines for use in Cocoa applications?
  • Next by Date: Re: Can you provide some code advice for a newbie please?
  • Previous by thread: Re: IB Binding no error, Programmatic Binding error
  • Next by thread: Re: Can you provide some code advice for a newbie please?
  • Index(es):
    • Date
    • Thread