• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie: Cannot use object as a parameter to a method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie: Cannot use object as a parameter to a method


  • Subject: Re: Newbie: Cannot use object as a parameter to a method
  • From: David Remahl <email@hidden>
  • Date: Thu, 22 Apr 2004 21:20:18 +0200

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You never pass around objects in Objective-C, just pointers to them!

Change:

- (NSString)rollAsString;

to:

- (NSString *)rollAsString;

in both places, and it should work fine.

/ Regards, David

On 22 apr 2004, at 21.04, Michael S. Tashbook wrote:

On 22 Apr 2004, at 19:07, Michael S. Tashbook wrote:
I'm trying to create a simple class that represents a six-sided die.
XCode keeps complaining about my rollAsInt method, which is just
supposed to return the value of the currValue instance variable (the
code below omits a similar method that returns the value as an
NSString,
which gives the same error message).

Hmmm... That's odd. Everything seems to work fine when I comment out the
*other* method in my class; I had previously omitted it because it
generated the same error message, and I figured that there was something
more general to blame.

Here are my two class source code files, in their entirety. When I
uncomment the rollAsString method, I get the original "Can not use an
object as a parameter to a method" error message.

As a side note, XCode also reports that rollAsString has an incompatible
return type. According to the O'Reilly book, the @"" form should
automatically create an NSString object, which is what the method is
declared to return. Did I miss a memo somewhere? ;)

Any ideas?

Mike


CWDie.h:

/* CWDie */

#import <Cocoa/Cocoa.h>

@interface CWDie : NSObject
{
int currValue;
}

- (void)roll;
- (int)rollAsInt;
- (NSString)rollAsString;

@end


CWDie.m:

#import "CWDie.h"

@implementation CWDie
- (void)roll
{
currValue = (rand() % 6) + 1;
NSLog(@"Rolled a %d.\n", currValue);
}

- (int)rollAsInt
{
return currValue; // XCode reports the error here
}


- (NSString)rollAsString
{ // XCode reports the error here
return @"foo"; // Just a placeholder statement for now
}

@end

- --- PGP key information---
pub 1024D/ 87256085 2003/06/12 David Remahl <email@hidden>
Web: http://ittpoi.com/david_remahl.asc
Fingerprint: 0C38 293C 86A9 7756 9CEA 4ED6 1651 620E 8725 6085
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)

iD8DBQFAiBrEFlFiDoclYIURAiRgAJ9Npkq142WF8z/uTElo6JOj5sKOiwCfUuze
a5qX9QFqMRxmVIoBEafJGuA=
=7fPp
-----END PGP SIGNATURE-----
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Newbie: Cannot use object as a parameter to a method (From: "Michael S. Tashbook" <email@hidden>)

  • Prev by Date: Re: Loading/Unloading a Cocoa-using framework from a CFM application
  • Next by Date: Re: Newbie: Cannot use object as a parameter to a method -- SOLVED
  • Previous by thread: Re: Newbie: Cannot use object as a parameter to a method
  • Next by thread: Re: Newbie: Cannot use object as a parameter to a method
  • Index(es):
    • Date
    • Thread