Ask a Question related to Mac Programming, Design and Development.

  1. #1

    Default Object Instances

    Another source told me a reason I'm goofing on my program (see 'Absurdly
    Easy Cocoa Question') is that I'm not calling instance methods on object
    instances. In fact, I didn't create any instances.

    BUT...various nib-based program models I'm using for my program don't have
    this line:


    NSObject *object = [[NSObject alloc] init];

    and I assume therefore don't create instances. Yet they use instance methods
    and work error and warning free.

    For example, Apple's currency converter has no sign of object instances:
    [url]http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCTutorial/chapt[/url]
    er03/chapter_3_section_7.html

    What gives? Thanks.

    --
    "love is
    the search beneath one's spamguy **at** foxchange(.)com
    tiny expectations"

    Will Oram Guest

  2. Similar Questions and Discussions

    1. return object instances
      hello, since I'm new to the world of object oriented programming I hope I use the right terms for the concerned things, but I'll try. I was...
    2. CF7 instances
      I wish to create for each subdirectory a new CF7 instance - like this: https://secure.domain.com/my_CF7_instance1/hello.cfm and ...
    3. Multiple app instances using same shared object.
      yeah you can Connect SharedObjects between instances of the same app and even instances of two diffrent apps. you need to use proxied sharedObjects...
    4. Unwanted mc instances - is it me?
      hmm. Just had a look at your movie, and it doesn't look like thats exactly what it does... You have tried starting your levels for swapDepths at...
    5. Object Instances: Never Mind
      Bleh, I'm a twit. After last post but before Mr. Ash's, I figured out my problem. I was referencing a class (ThermCalc is its name), not an outlet...
  3. #2

    Default Re: Object Instances

    Will Oram <spamguy@ihate.spammers.com> wrote in message news:<BB2E0B61.A8E0%spamguy@ihate.spammers.com>...
    > Another source told me a reason I'm goofing on my program (see 'Absurdly
    > Easy Cocoa Question') is that I'm not calling instance methods on object
    > instances. In fact, I didn't create any instances.
    >
    > BUT...various nib-based program models I'm using for my program don't have
    > this line:
    >
    >
    > NSObject *object = [[NSObject alloc] init];
    Nibs do create instances. However, the way they create them is somewhat different.
    Eric Pepke Guest

  4. #3

    Default Re: Object Instances

    On 7.7.2003 11.21 AM, in article tph-2D90C1.10213407072003@localhost, "Tom
    Harrington" <tph@pcisys.no.spam.dammit.net> wrote:

    I was admittedly rather vague with my generic code example, so I need to
    clarify.
    > Assuming that "Object" is the name of the class,
    It's not; it's the instantiated class from the nib. I realised I omitted a
    description of it after I posted -- sorry. Nevertheless the header I've
    always been using is effectively similar to your
    >
    > - (int) calcNewValue:(int)currentValue;
    ---
    >>
    >> ** Actually I get three warnings:
    >> - the one I mentioned
    >> - return type for the method defaults to id (but the variable it returns is
    >> an integer!)
    >
    > This is the default when no method signature is found; just as C
    > defaults to assuming an undeclared function returns int, Obj-C defaults
    > to assuming that an undeclared method returns id. The method doesn't
    > return int because (as I explained above) it doesn't exist in the form
    > that you're trying to call.
    It should be. If Object is an instance created from a nib-created class,
    then wouldnąt the header I normally use (the one above) work?
    >
    > I think maybe you need to sit down and read up a bit on object-oriented
    > programming, and on Cocoa and Objective C.
    I was a tad ambiguous last post, so it no doubt confused you. But don't be
    ready to call me not well-read just yet...that's why I have Cocoa
    documentation, an O'Reilly text, various printouts, and Apple's online texts
    at close hand at all times when I work. These don't do anything if I don't
    try the code! Heck, the only way I learned Carbon was a) Macintosh-C, b)
    this newsgroup, and c) toying around.

    Thanks.

    --
    "love is
    the search beneath one's spamguy **at** foxchange(.)com
    tiny expectations"

    Will Oram Guest

  5. #4

    Default Re: Object Instances

    An update now.

    I tried the alternative header (for class methods) and it worked. But this
    goes against what I asked earlier about nibs and objects, doesn't it?
    Quoting you, Mr. Harrington:

    "You can create your instances in Interface
    Builder, if it's appropriate to the situation."

    'Object' in my code, in this case, happens to be an instantiated controller
    object. Shouldn't it receive instance, not class, methods then?

    Thanks.

    --
    "love is
    the search beneath one's spamguy **at** foxchange(.)com
    tiny expectations"

    Will Oram Guest

  6. #5

    Default Re: Object Instances

    In article <BB2FCA95.A938%spamguy@ihate.spammers.com>,
    Will Oram <spamguy@ihate.spammers.com> wrote:
    > 'Object' in my code, in this case, happens to be an instantiated controller
    > object. Shouldn't it receive instance, not class, methods then?
    Object is also the name of a class in the frameworks. It's old, and kept
    around mostly for compatability reasons, but it's there. Change the name
    of your variable. Apparently the class's name takes precedence over your
    variable's name.

    The general convention is to make your class names begin with an
    uppercase letter and make your variables begin with a lowercase letter.
    If you do that you'll avoid this problem.
    Michael Ash Guest

  7. #6

    Default Re: Object Instances

    Mark Haase wrote:
    >
    > In article <BB2E1474.A908%spamguy@ihate.spammers.com>,
    > Will Oram <spamguy@ihate.spammers.com> wrote:
    >
    > > I get a warning claiming it can't find the class (factory) method?** I was
    > > unsure which object to use in 'Object''s place...I expected it to be the
    > > object that contains the method's header and body. Instead, I get this
    > > warning no matter *what* object I insert there.
    >
    > A factory method is a method that returns an a new instance of an
    > object, but isn't a constructor. The Cocoa API has lots of these. Look
    > at all the class methods for NSString (they are marked with +'s).
    Close, but not quite.

    In Obj-C parlance, a "factory" method is any class method. Not all
    factory methods create instances. Methods that create objects are
    +alloc, -copy, and what we refer to as "convenience methods", such as
    +stringWithFormat: or -stringByAppendingString:.

    -jcr
    John C. Randolph Guest

Posting Permissions

  • You may not post new threads
  • You may 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