views:

103

answers:

2

I usually have no problems using NSEnumerator in the iPhone sdk but this is my first time using it within the DrawRect function of a UIView. The NSEnumerator iterator is causing an error: request for member "(member)" in something not a structure or union.

1) Why is this happening?
2) How can I workaround it?

(P.S. the member not being recognized is a properly declared and synthesized property of an NSObject Subclass whose .h file is properly imported in the UIView .m file whose drawRect function calls the NSEnumerator)

+1  A: 

It's hard to say without seeing the code. But typically the compiler issues that error when you have something like this:

@interface MyClass : NSObject {
  int someValue;
}
@end

.... and then in implementation....

MyClass *aPointer;

int index = aPointer.someValue;

In this case, you'd actually want

int index = aPointer->someValue;

Obviously the syntax differs a little for properties. You assert that the property is properly declared and synthesized, but obviously the compiler disagrees. I'm not sure how much help anyone can give you without seeing some code excerpts, though. It's extremely unlikely that NSEnumerator itself is not recognizing your member. Rather, some code you wrote in the context of that iterator has a typo.

peterb
Thanks, this got me thinking. I fixed the problem by setrting the NSEnumerator object to my custom class's type instead of just 'id'.
RexOnRoids
+2  A: 

The other thing to remember is that NSEnumerator returns ids, not object pointers (unless you're casting them). An id has no properties, so ANY attempt to access a property on an id will fail. As peterb said, seeing code will help a lot here.

Ben Gottlieb
Yes! I forgot to set the object to my Custom Class type instead of id. This helped. Thanks.
RexOnRoids