Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jordan72

macrumors member
Original poster
Nov 23, 2005
88
0
What syntax do I need so the XCode compiler accepts both id and id* types without giving me warnings? Although the compiler warnings don't turn into exceptions that stop my program in it's tracks or change my program logic, I heard it's good practice to remove all warnings and want to remove the warnings.

Code:
-method:(id)

-method:(id*)

I tried both versions by passing them both id and id* and my program worked fine, but how do I remove warnings with better syntax?


Since I'm on the topic of removing warnings, I can't seem to get rid of these kinds of warnings either.

I've only declared -(NSString *)set once:

Code:
[[sets objectAtIndex:i] omega:[[[sets objectAtIndex:i] set] length]-1];

warning: multiple declarations for method `set'


I never did declare -(int)length, so I don't know why it doesn't know what the heck is going on, since -(int)length is an NSString method.

Code:
[self possible:[self possible] * [[[sets objectAtIndex:i] set] length]];

warning: multiple declarations for method `length'
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
You can't. A method in an ObjC class cannot be overloaded like it can in C++. You can't do what you are trying to do.

Why do you want to be able to pass id* anyway? id is already a pointer (it's declared as void* or obj_class* anyway).
 

Jordan72

macrumors member
Original poster
Nov 23, 2005
88
0
I don't know what overloading is, but what I did describe up there worked fine, just got warnings.

Why id*? For the same reason of NSArray method:

Code:
- (id)initWithObjects:(id *)objects count:(unsigned)count

I'm merely following established conventions. We both want pointers to objects for our own purposes.

I did figure out the first part of the question. I just made my id an id*.

But I still don't know why I'm getting those others warnings, I bet it's something really simple.
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
- (id)initWithObjects:(id *)objects count:(unsigned)count

Although it's possible to do stuff yourself like the above in objective-C it's much more common to send a group of objects in an array or a dictionary (depending upon your needs). Something like

[myObject myMethodWithArray:[NSArray arrayWithObjects: one, two, three, nil]];

Although my example is obviously more verbose and slower when you only ever use immutable objects I think the method is much more flexible if it can take any old array not just a list of objects. You also get to use the NSArray methods to access the elements rather than messing about with pointer arithmetic.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.