Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics (Retired) Introduction to Objective-C Introducing @property

Armend Azemi
Armend Azemi
27,921 Points

How to acceses and give a value to the NSArray* center and how to print it.

So we have learned how to call upon the methods by setters and getters then assigning values to them. But we have only done this for the float.

I have 3 questions.

  1. So my first question is, how do you do this for the NSArray* center? I want to call the method and assign it some values.

  2. What "types" of values can i assign the NSArray? Can i assign it to be a array of chars, or an array of floats?

3 Last question is for the getter. When we declare the setter for example:

-(float)radius { return _radius }

Why are we returing the _radius? Since we have also assigned "_radius" to the variable "radius" what happends when we call it in the NSlog?

Example: NSlog(@"\nball radius is %f", [ball radius]);

As the above, radius is the same as _radius. But what does _radius contain?

Sorry for wall of text, but i just dont feel comertable moving on unless i have understood everyhting otherwise it feels like im never going to understand.

Best regards Armend

2 Answers

hi , when you talk about array in IOS you should tell us are you using Swift or Objective-C , in swift you can append value to the array by using

var myArray = ["hi","Hello"]

adding value myArray.apped("Hello Again")

in Objective-C there is two type of array first type you cannot append value , and other you can .

about how to access array element ,

in swift myarray[indexOfelement]

in Objective-C myarray.getValueByIndex[index]

im not sure 100% about spell in Objective-C try to figure out .

about getter and setter

keep in minde , when you have a class and this class have for example var a , if you want the value of var a for example not less than 10 or anythings else , you should set setter , and whenever you set a setter you should have getter as well .

hopefully clear .

Armend Azemi
Armend Azemi
27,921 Points

Ye i did clearify abit.

Thanks alot!

pls mark your question as answered