Professional Web Applications Themes

framework referencing framework? - Mac Programming

(this is x-posted to comp.sys.mac.programmer.help and comp.lang.objective-c, since I wasn't sure which was more appropriate) I don't know how to structure this. I have a framework ("foo") that needs to reference another framework ("bar"). One of the eventual applications will need to include "foo" and "bar" as well. I don't care for the idea of including the "bar" framework inside "foo", but it seems to be the only way to do it. Here's how the code looks: class bar; interface foo : NSObject { id obj; } -(id) doSomethingWithBar:(bar*) myBar; end implementation foo -(id) doSomethingWithBar:(bar*) myBar { baz* myBaz = ...

  1. #1

    Default framework referencing framework?

    (this is x-posted to comp.sys.mac.programmer.help and
    comp.lang.objective-c, since I wasn't sure which was more appropriate)

    I don't know how to structure this. I have a framework ("foo") that
    needs to reference another framework ("bar"). One of the eventual
    applications will need to include "foo" and "bar" as well.

    I don't care for the idea of including the "bar" framework inside "foo",
    but it seems to be the only way to do it. Here's how the code looks:

    class bar;

    interface foo : NSObject {
    id obj;
    }

    -(id) doSomethingWithBar:(bar*) myBar;

    end

    implementation foo

    -(id) doSomethingWithBar:(bar*) myBar {
    baz* myBaz = [myBar someMethod];
    Mike Guest

  2. #2

    Default Re: framework referencing framework?

    In article <comcast.net>,
    Mike Binkley <com> wrote:

    [snip] 

    Does #importing the other framework's header file force you to link
    against it? If not, that's the way to go.

    Otherwise, you should probably change all of your Bar references to use
    a protocol instead. That is, I think, the correct approach if you don't
    want to rely on an external library. Another approach is to delare an
    informal protocol, like so:

    interface NSObject (MyInformalProtocol)
    - methods...
    end

    Pass everything around as ids, and you're good.
    Michael Guest

  3. #3

    Default Re: framework referencing framework?

    > Otherwise, you should probably change all of your Bar references to use 

    How can I go about doing this? I'm foggy on implementing protocols. I
    have an informal protocol running with things passed as IDs, but if
    there's a way I can do it w/o mucking around with NSObject like the
    informal one does, I'd prefer it.

    I just don't see how to declare a formal protocol for the bar object
    that makes the foo object know what bar can do. I thought formal
    protocols were only to define what bar has to implement itself.

    -Bink.
    Mike Guest

  4. #4

    Default Re: framework referencing framework?

    In article <comcast.net>,
    Mike Binkley <com> wrote:
     
    >
    > How can I go about doing this? I'm foggy on implementing protocols. I
    > have an informal protocol running with things passed as IDs, but if
    > there's a way I can do it w/o mucking around with NSObject like the
    > informal one does, I'd prefer it.[/ref]

    Informal protocols don't 'muck around with' NSObject, really. They just
    use it as a convenient place to declare the methods. They have no effect
    on anything once your code is compiled, though. They are obviously
    considered ok by Apple, as they use them all over the place.
     

    It's pretty simple. You declare your protocol as usual:

    protocol BlahActionSomething <NSObject>
    -methods...
    end

    (This protocol is declared as conforming to NSObject so that you can
    call things like -retain and -release on objects declared to conform to
    this protocol without warnings.)

    As you seem to know already, you can declare that your class conforms to
    this protocol:

    class Blah : NSObject <BlahActionSomething>
    .....
    end

    Now you can use the id <protocol> type to declare that a method takes an
    object that conforms to a particular protocol:

    - methodWithObject:(id <BlahActionSomething>)obj;

    Here, the complier understands that this is not a totally unknown
    object, but rather it's an object of unknown class that conforms to your
    protocol, so it will let you send any message in your protocol without
    warning you. You can use this for instance variables, or any other place
    where a type is required as well.
    Michael Guest

Similar Threads

  1. php framework
    By Kenny in forum PHP Development
    Replies: 2
    Last Post: October 21st, 08:44 PM
  2. .NET Framework 1.1
    By Marcelo in forum ASP.NET Web Services
    Replies: 1
    Last Post: August 13th, 01:12 PM
  3. ASP.net in other framework
    By Anne in forum ASP.NET General
    Replies: 2
    Last Post: July 10th, 05:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139