Amazon.com Widgets Exercise 8.5 - Can someone please explain this error and how to fix it?
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 20, 2013, 04:46:54 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  Exercises
| | |-+  Chapter 8
| | | |-+  Exercise 8.5 - Can someone please explain this error and how to fix it?
Pages: [1]   Go Down
Print
Author Topic: Exercise 8.5 - Can someone please explain this error and how to fix it?  (Read 874 times)
AnthGee
Newbie
*
Posts: 3






« on: April 02, 2012, 02:48:08 AM »

Hi

I am at the stage where I need to define a new class "Circle" and make it a subclass of the GraphicObject class.

My circle.h and circle.m file is as follows:

#import "GraphicObject.h"

@interface Circle : GraphicObject

@property float radius;

-(void) setRadius: (float) r;


@end



#import "Circle.h"

@implementation Circle

@synthesize radius;

-(void) setRadius: (float) r;   // this is where I receive an error
{
    radius = r;
}

@end


I have the following error come up for my implementation file for the setRadius method being "Writable atomic property 'radius' cannot pair a synthesized setter/getter with a user defined setter/getter".

What does this error mean and what is the correct code?

Any assistance will be greatly appreciated.

Thanks
Logged
jgross
Newbie
*
Posts: 8






« Reply #1 on: April 06, 2012, 03:57:15 PM »

If you are going to define a method as a property, then you don't want to manually define it in the body.  Simply delete the manual declaration.  Within you main.m class you'll be able to access the radius variable using dot notation.  If you define a new circle object named circ0 you could then set it's radius with the statement circ0.radius = 3.5;  Similarly, you could write an NSLog statement to print the radius like so: NSLog(@"Radius = %f", circ0.radius);  You can also access these synthesized methods (hence the synthesize directive in the implementation file) with bracketed notation as well.  Someone more experienced could correct me here, but I believe the notation would be [circ0 setradius = some value] and some expression = [circ0 radius]  Hope that helps.

Jim
Logged
AnthGee
Newbie
*
Posts: 3






« Reply #2 on: April 06, 2012, 11:29:44 PM »

Thanks Jim

Understand this now.

By removing my method I was still able to set the radius by either using:

myCircle.radius = 5.5

or

[myCircle setRadius = 5.5]

Logged
clouded
Full Member
***
Posts: 123






« Reply #3 on: May 17, 2012, 12:35:01 PM »


-(void) setRadius: (float) r;   // this is where I receive an error
{
    radius = r;
}

@end[/color]


it may be: -(void) setRadius: (float) r;   <-- extra semicolon???
Logged
Gordio
Newbie
*
Posts: 12


Email




« Reply #4 on: July 14, 2012, 11:43:02 AM »

I had the same error.  it's harmless, but the reason it happened anyway is how you named it.

When you synthesize "radius" setRadius is already created.  So when you created a method setRadius, which already exists since you synthesized "radius", it had that yellow triangle warning.

For example, if you renamed the method "setCircleRadius" while keeping the synthesized "radius" spelling the way it is, the error will be gone.
Logged
duducaribeiro
Newbie
*
Posts: 4


Email




« Reply #5 on: October 02, 2012, 07:29:09 AM »

Its possible to create a method with the same name created when you synthesize radius.

The problem AnthGee code was the semicolon at the end of the method name. It should be included in the interface file, but not in the implementation indicated by clouded post.
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.