Project 1:
In Xcode start a new project: Framework; I named it Adder. Drag
add1.c
and add2.c
(from this post or the linked project files) into Classes. Write declarations of the two functions into a new file adder.h
and drag that in too. I removed the unused Cocoa, Foundation and AppKit Frameworks under External Frameworks .. Build it (Release config). Now, from the Desktop do:
This is like what we've done before, except for the -F flag which tells the linker where to look for our framework now, at link time. At run time, it will look in a few standard locations, one of which is
~/Library/Frameworks
. So move the Adder.framework
there (from Adder/build/Release
). And it works:Project 2:
This one is for a simple "Foundation tool" that loads code from a bundle at runtime. We've seen a bit of that before (here and a few other posts). It makes you appreciate the whole Framework approach, because the natural question is, once I've got it working, where do I put the bundle? You can put it in
Library/Application Support
or something, but it's an issue. The example also introduces the notion of a Protocol.The code listing for 3 files is given below. The first two,
BundlePrinter.h
and SimpleMessage.m
go into a new Xcode project: a Cocoa Bundle named SimpleMessage. Set the Principal Class for SimpleMessage: under Resources > Info.plist > Principal Class > SimpleMessage.Next start a second new Xcode project: Command Line Tool > Foundation, named BundlePrinter. Put in
BundlePrinter.m
and another copy of BundlePrinter.h
. Build it.Copy
SimpleMessage.bundle
to BundlePrinter/build/Release
. In Xcode, run BundlePrinter from the Console:
It works!
BundlePrinter.h
SimpleMessage.m
BundlePrinter.m
That's the first time I've ever used
goto
(and probably the last).