• 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
Re: CoreFoundation Command Line Tool - an easy beginner question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreFoundation Command Line Tool - an easy beginner question


  • Subject: Re: CoreFoundation Command Line Tool - an easy beginner question
  • From: Chris Parker <email@hidden>
  • Date: Mon, 4 Aug 2008 12:48:07 -0700


On Aug 4, 2008, at 11:51 AM, Steve Cronin wrote:

Here's the pretty simple tool I'm trying to create (THANK-YOU Michael Ash!!)

int main (int argc, const char * argv[]) {
char dummy;
read(STDIN_FILENO, &dummy, 1);
[NSAutoreleasePool new];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]];
LSOpenCFURLRef((CFURLRef)url, NULL);
return 0;
}


I'm using XCode3.1 with the 10.5 SDK deploying to 10.4.
I open new project using the CoreFoundation - Command Line Tool template, and place the code shown above.

You've created a CoreFoundation tool from the template, but you're using Foundation code (NSString, NSURL, etc.). You really want to be creating a Foundation tool (there's a template for that too).


Creating a CoreFoundation tool creates a pure C configuration in the project, which has no idea how to deal with Objective C.

My question is what are the #imports necessary to make this work?
I have figured out:
#import <unistd.h> //for the STDIN_FILENO and the read()
#import <ApplicationServices/ApplicationServices.h> //for the LSOpenCFURLRef


I've tried various usages of #import <Foundation/Foundation.h> but can't seem to get it right so that NSURL & NSAutoreleasePool are defined...
I believe that both NSURL and NSAutoreleasePool are defined in the Foundation framework, which is why I am focused on getting it #imported, I just need the syntax..
(with Foundation framework added to the project)
NO --> #include <Foundation/Foundation.h> (~700 errors...)
NO --> #include <Foundation/NSURL.h> (45 errors..)


Oh out of exasperation, I tried <Cocoa/Cocoa.h> ---> ~1700 errors

I know this is probably pretty easy for most, but its got me just bamboozled....

Creating a Foundation tool instead will get you a lot farther. :)

As far as parsing arguments go, you may wish to look at using [[NSProcessInfo processInfo] arguments], which gives you an NSArray of NSStrings of the arguments.

.chris

--
Chris Parker
Cocoa Frameworks
Apple, Inc.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >CoreFoundation Command Line Tool - an easy beginner question (From: Steve Cronin <email@hidden>)

  • Prev by Date: Re: CoreFoundation Command Line Tool - an easy beginner question
  • Next by Date: Re: Dependent NSOperations (and best practices)
  • Previous by thread: Re: CoreFoundation Command Line Tool - an easy beginner question
  • Next by thread: Automatic population of NSTableView with custom columns at launch time
  • Index(es):
    • Date
    • Thread