Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Armend Azemi
Armend Azemi
24,545 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
24,545 Points

Ye i did clearify abit.

Thanks alot!

pls mark your question as answered