Foundation vs Core Foundation

  • I'm new to OSX/Cocoa, coming from Solaris. I'm porting the functionality of a
    Solaris connection server to Mac OS X. "Porting" isn't exactly the right word
    since I'm taking the liberty to use Cocoa and whatever else OSX offers to get
    things working well, including rearchitecting.

    Before I start down the wrong path: What is the difference between a Foundation
    tool and a Core Foundation tool? Primarily I will be needing to use TCP/IP
    sockets, file I/O, and multithreading, so is one a better fit than the other? I
    believe OSX calls this type of GUI-less background process a 'daemon'. This
    would be for Snow Leopard.

    Thanks,
    -Jon
  • Jon Sigman <mailto:<rf_egr...> wrote (Monday, November 29,
    2010 12:59 PM -0800):

    > Before I start down the wrong path: What is the difference
    > between a Foundation tool and a Core Foundation tool?

    Short answer:

    Foundation: Objective-C
    Core Foundation: C

    If you plan to write your high-level coding using Objective-C,
    you'll want to build a Foundation tool. Note that your
    Objective-C code will have full access to the underlying Core
    Foundation, and you can freely mix C and Objective-C code (ObjC
    being a strict super-set of C).

    --
    James Bucanek
  • > Before I start down the wrong path: What is the difference between a Foundation
    > tool and a Core Foundation tool? Primarily I will be needing to use TCP/IP
    > sockets, file I/O, and multithreading, so is one a better fit than the other? I
    > believe OSX calls this type of GUI-less background process a 'daemon'. This
    > would be for Snow Leopard.

    CoreFoundation is a general-purpose C framework whereas Foundation is
    a general-purpose Objective-C framework. Both provide collection
    classes, run loops, etc, and many of the Foundation classes are
    wrappers around the CF equivalents. CF is mostly open-source (see
    http://opensource.apple.com/source/CF/CF-550.42/), and Foundation is
    closed-source.

    Typically there's little reason to confine oneself to CF as it'll only
    make your life more difficult. The only exception is when security is
    a concern; I'm not sure what the current recommendation is on linking
    Foundation from a process that runs as root (although I believe some
    of Apple's software does this.) Will your daemon be running as root?
  • On Mon, Nov 29, 2010 at 2:59 PM, Jon Sigman <rf_egr...> wrote:
    >
    > Before I start down the wrong path: What is the difference between a Foundation
    > tool and a Core Foundation tool?

    You mean, the project types when you start a new project in Xcode?

    A Core Foundation tool links against (you guessed it)
    CoreFoundation.framework, and starts you off with a .c file that
    #includes <CoreFoundation/CoreFoundation.h>. A Foundation tool also
    links against (another big surprise here) Foundation.framework and
    libobjc, and it starts you off with a .m file that #imports
    <Foundation/Foundation.h>.

    > Primarily I will be needing to use TCP/IP
    > sockets, file I/O, and multithreading, so is one a better fit than the other?

    Both frameworks have similar capabilities in this regard - the
    question is what language you want to use. Core Foundation exposes a C
    API; Foundation, an Objective-C API. The latter is a bit higher level,
    so you'll sometimes find Foundation-based code also calling various CF
    functions when it needs more detailed, lower-level access to something
    that's abstracted in Foundation.

    Honestly though, if you have working Unix-style code that uses BSD
    sockets, file descriptors, and pthreads functions, why rewrite it? Mac
    OS X *is* Unix, after all - for something like you're describing, I'd
    expect very few changes required to either the code or the make file.
    You could probably use it mostly as-is, and simply write a launchd
    plist to replace the init script that Solaris uses.

    sherm--

    --
    Cocoa programming in Perl:
    http://camelbones.sourceforge.net
  • It sounds like Foundation is the safer way to go, especially to safeguard future
    functionality expansion. I take it Foundation does not contain Core Foundation,
    but at least they're not mutually exclusive? If I go Foundation, I can include
    Core Foundation as well, should I want something in it, since it's just C?
  • On Nov 29, 2010, at 2:18 PM, Jon Sigman wrote:

    > It sounds like Foundation is the safer way to go, especially to safeguard future
    > functionality expansion. I take it Foundation does not contain Core Foundation,
    > but at least they're not mutually exclusive?

    No; many of the classes in Foundation simply wrap CoreFoundation objects. You can even cast Foundation objects to CoreFoundation objects, and they'll work (with a few exceptions, such as NS/CFRunLoop and NS/CFBundle). Search for "toll free bridging" on ADC for more information.

    > If I go Foundation, I can include
    > Core Foundation as well, should I want something in it, since it's just C?

    Yes.

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • On Nov 29, 2010, at 4:18 PM, Jon Sigman wrote:

    > It sounds like Foundation is the safer way to go, especially to safeguard future
    > functionality expansion. I take it Foundation does not contain Core Foundation,
    > but at least they're not mutually exclusive?

    Check  out AsyncSocket as an example that wraps Core Foundation sockets and streams in Foundation/Objective-C classes, and may also be a useful addition to your project:

    http://www.cocoadev.com/index.pl?AsyncSocket

    Aaron
previous month november 2010 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Go to today