Nigel
Nigel

Reputation: 604

Use of nested references in objective C

Getting an error message "Nested functions are disabled, use -fnested" etc in XCode/ObjC.

Here's the code (balls is an NSMutableArray pointing at a bunch of UIViews).

CGPoint pos=[[self.balls objectAtIndex:pointidx] center];

But the following seems to compile ok.

UIView *ref=[self.balls objectAtIndex:pointidx];
CGPoint pos=ref.center;

Should I use "-fnested-functions to re-enable (and if so where do I put the "-fnested-functions")? Or should I just put up with additional step of creating a UIView* pointer first? ty.

Upvotes: 2

Views: 385

Answers (1)

David Kanarek
David Kanarek

Reputation: 12613

Generally when you see nested functions warnings, what you really have is a syntax error.

Is pointidx an integer and balls an NSArray? Also, do you have a property for balls? Try just balls instead of self.balls.

Edit: Since it's a compile time thing, I'm thinking maybe it doesn't like passing center to NSObject. What happens if you cast the object:

CGPoint pos=[(UIView *)([self.balls objectAtIndex:pointidx]) center];

Irrelevant musing obfuscated.

Upvotes: 1

Related Questions