Ask a Question related to Mac Programming, Design and Development.
-
Bruce Coughlin #1
Objective C -> C
1) Is there a good book for C programmers to be able to read Objective C
code examples? I just want to know the basics for translation.
2) I'm trying to translate some code to C and am scratching my head a few
places. Here are the mysterious lines to me (not the entire function):
before the function:
- (IBAction) Install:(id)sender
inside the function:
NSBundle*myBundle = [NSBundle mainBundle];
NSString*path = [myBundle pathForResource:@"theDataFork" ofType:@"rsrc"];
NSURL *urlRef = [[NSURL alloc] initFileURLWithPath:path];
I have no idea what the line before the function means.
My guess on the first line inside the function:
CFBundleRef myBundle = CFBundleGetMainBundle();
for the next two, combine to one call:
CFURLRef urlRef =
CFBundleCopyResourceURL(myBundle,CFSTR("theDataFor k"),CFSTR("rsrc"),NULL);
though perhaps a CFURLCreate... function is correct, I don't know, but that
gets into CFAllocators.
Thanks for any insight.
-- Mac program, CW8 in C
Bruce Coughlin Guest
-
Minolta SRT200 objective change ?
Q: Just how to release the objective on a Minolta SRT200? Cannot find the switch or whatever, and have gone and bought a few fine lenses to be used... -
matt neuburg #2
Re: Objective C -> C
In <BB7A8FFF.ADE%brucecoughlin@nyc.rr.com> Bruce Coughlin wrote:
An excellent book is on your computer. In fact, the book on Objective-C> 1) Is there a good book for C programmers to be able to read Objective
> C code examples?
on your computer is one of the best computer books I've ever read, on
any subject.
There is no "translation". Objective-C is a C superset, not C in French.> I just want to know the basics for translation
Because you don't know Objective-C. Learn it. It takes about an hour. m.> 2) I'm trying to translate some code to C and am scratching my head a
> few places
--
matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt[/url]
REALbasic: The Definitive Guide! 2nd edition!
[url]http://www.amazon.com/exec/obidos/ASIN/0596001770/somethingsbymatt[/url]
Subscribe to TidBITS. It's free and smart.
matt neuburg Guest
-
Paul Mitchum #3
Re: Objective C -> C
Bruce Coughlin <brucecoughlin@nyc.rr.com> wrote:
Much of the Cocoa Foundation is 'toll-free bridged' with CoreFoundation> 1) Is there a good book for C programmers to be able to read Objective C
> code examples? I just want to know the basics for translation.
>
> 2) I'm trying to translate some code to C and am scratching my head a few
> places. Here are the mysterious lines to me (not the entire function):
>
> before the function:
> - (IBAction) Install:(id)sender
>
> inside the function:
>
> NSBundle*myBundle = [NSBundle mainBundle];
>
> NSString*path = [myBundle pathForResource:@"theDataFork" ofType:@"rsrc"];
> NSURL *urlRef = [[NSURL alloc] initFileURLWithPath:path];
>
>
> I have no idea what the line before the function means.
> My guess on the first line inside the function:
>
> CFBundleRef myBundle = CFBundleGetMainBundle();
>
> for the next two, combine to one call:
>
> CFURLRef urlRef =
> CFBundleCopyResourceURL(myBundle,CFSTR("theDataFor k"),CFSTR("rsrc"),NULL);
>
> though perhaps a CFURLCreate... function is correct, I don't know, but that
> gets into CFAllocators.
>
> Thanks for any insight.
>
> -- Mac program, CW8 in C
objects, so you're generally right to make the assumptions about
CFWhatever.
That said, you can install the Apple Developer Tools and compile
Objective-C/Cocoa programs. All for free, without translating it to
CoreFoundation.
My advice: Install the dev tools, learn enough Cocoa that you know an
IBAction and an id are, and then do the translation. You might find that
you've lost all momentum toward translating it to CoreFoundation, since
Cocoa does all the heavy lifting for you.
Paul Mitchum Guest
-
brucecoughlin #4
Re: Objective C -> C
> My advice: Install the dev tools, learn enough Cocoa that you know an
Oooo you might be right, but this is a very small function in a much larger> IBAction and an id are, and then do the translation. You might find that
> you've lost all momentum toward translating it to CoreFoundation, since
> Cocoa does all the heavy lifting for you.
(finished) C program. For future apps you're probably correct.
brucecoughlin Guest
-
David Phillip Oster #5
Re: Objective C -> C
In article <BB7A8FFF.ADE%brucecoughlin@nyc.rr.com>,
Bruce Coughlin <brucecoughlin@nyc.rr.com> wrote:
I like the Hillegas book: "Cocoa Programming for Max OS X". "The Vermont> 1) Is there a good book for C programmers to be able to read Objective C
> code examples? I just want to know the basics for translation.
Recipes" are also good, and was available free online.
<http://www.stepwise.com/Articles/VermontRecipes/>
For free, you can get:
Inside Mac OS X: Object-Oriented Programming and the Objective-C
Language, Apple's Objective-C documentation
<http://developer.apple.com/techpubs/macosx/Cocoa/ObjectiveC/ObjC.pdf>
It is probably already on your machine in
/Developer/Documentation/Cocoa/ObjectiveC/
think:> 2) I'm trying to translate some code to C and am scratching my head a few
> places. Here are the mysterious lines to me (not the entire function):
>
> before the function:
> - (IBAction) Install:(id)sender
> I have no idea what the line before the function means.
extern IBAction Install(id sender);
and you won't be far wrong.
David Phillip Oster Guest
-
Eric Pepke #6
Re: Objective C -> C
Bruce Coughlin <brucecoughlin@nyc.rr.com> wrote in message news:<BB7A8FFF.ADE%brucecoughlin@nyc.rr.com>...
I second the recommendation for "The Objective C Programming Language"> 1) Is there a good book for C programmers to be able to read Objective C
> code examples? I just want to know the basics for translation.
on your computer.
However, your problem seems to be more converting between Cocoa and
Carbon, which is beyond the difference between Objectve C and C.
In many cases there isn't a 1-to-1 translation between Cocoa and Carbon,
though sometimes you can get close. Primarily, though, they're very
different beasts. The Cocoa objects, which are provided in Objective C
and Java, provide a lot of compact functionality which takes a lot more
lines in Carbon.
This is the header; it's how Cocoa methods are declared. The minus sign> before the function:
> - (IBAction) Install:(id)sender
means it's an instance method, as opposed to a class method. If you
know C++, it corresponds roughly to
IBAction Foo::Install(id sender)
Except that IBAction, which is basically typedefed as void, also tells
the compiler that this can be linked as an action with a NIB file.
Eric Pepke Guest
-
Joe Davison #7
Re: Objective C -> C
On Tue, 02 Sep 2003, Bruce Coughlin wrote:
Of course, as others have pointed out, the Objective-C manual that comes> 1) Is there a good book for C programmers to be able to read
> Objective C code examples? I just want to know the basics for
> translation.
>
with the developers tools is one place to start.
It might help to know that Objective-C ~=~ C + Smalltalk. That is, if
you understand both Smalltalk and C, you'll find individual statements
easy to read.
I don't know if there's an option on the compiler, but Objective-C is
(or used to be) translated into C as the first step in compilation -- so
if you can get the output of that pass, your job is done for you.
Of course, if you're doing the translation in order to port the code,
you've got a problem, as the Cocoa frameworks are probably most of the
code in most applications.
Otherwise, why translate it?
joe
Joe Davison Guest



Reply With Quote

