Professional Web Applications Themes

Object Instances - Mac Programming

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/doentation/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"...

  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/doentation/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. #2

    Default Re: Object Instances

    Will Oram <spamguyihate.spammers.com> wrote in message news:<BB2E0B61.A8E0%spamguyihate.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

  3. #3

    Default Re: Object Instances

    On 7.7.2003 11.21 AM, in article tph-2D90C1.10213407072003localhost, "Tom
    Harrington" <tphpcisys.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
    doentation, 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

  4. #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

  5. #5

    Default Re: Object Instances

    In article <BB2FCA95.A938%spamguyihate.spammers.com>,
    Will Oram <spamguyihate.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

  6. #6

    Default Re: Object Instances

    Mark Haase wrote:
    >
    > In article <BB2E1474.A908%spamguyihate.spammers.com>,
    > Will Oram <spamguyihate.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

Similar Threads

  1. return object instances
    By vollja in forum Coldfusion - Advanced Techniques
    Replies: 7
    Last Post: July 27th, 09:28 PM
  2. CF7 instances
    By A_Sabrina in forum Macromedia ColdFusion
    Replies: 3
    Last Post: May 7th, 06:03 AM
  3. Multiple app instances using same shared object.
    By Berzy in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: February 18th, 11:26 AM
  4. Object Instances: Never Mind
    By Will Oram in forum Mac Programming
    Replies: 0
    Last Post: July 8th, 05:14 PM
  5. 2 Instances vs 2 DB's in SQL 2K
    By Chris Spiess in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: June 30th, 04:18 PM

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