• 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: EXC_BAD_ACCESS on returning an int?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EXC_BAD_ACCESS on returning an int?


  • Subject: Re: EXC_BAD_ACCESS on returning an int?
  • From: mmalc Crawford <email@hidden>
  • Date: Sat, 04 Jul 2009 23:56:46 -0700


On Jul 4, 2009, at 11:43 PM, Andrew Farmer wrote:

- (int)numberOfSides {
	return numberOfSides;
}
- (void)setNumberOfSides:(int)value {
		numberOfSides = value;
}
Let me guess: does your stack trace (type "tb" in the gdb console) indicate infinite recursion? Either synthesize accessors or write your own - but don't try to do both at once. Down that road lies madness.

This is not correct.

Certainly there is little point in using @synthesize if you're going to implement both the getter and setter, however it is perfectly reasonable to use @synthesize and still provide a custom implementation of one of the methods. The instruction to the compiler is to synthesize the methods *if it cannot find any other implementation*.
<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW14 >



In the case of the implementations provided here, both of them are valid and will not result in infinite recursion.


If the implementations had been:

- (int)numberOfSides {
	return self.numberOfSides;
}

and/or

- (void)setNumberOfSides:(int)value {
	self.numberOfSides = value;
}

then this would have resulted in infinite recursion.

mmalc

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >EXC_BAD_ACCESS on returning an int? (From: Ian Havelock <email@hidden>)
 >Re: EXC_BAD_ACCESS on returning an int? (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: EXC_BAD_ACCESS on returning an int?
  • Next by Date: [moderator] Re: leaking UIColor objects
  • Previous by thread: Re: EXC_BAD_ACCESS on returning an int?
  • Next by thread: Display either date part or time part in LOCAL format
  • Index(es):
    • Date
    • Thread