views:

384

answers:

2

Hello All,

I am having a problem with terminology I think. Is a ViewController the Controller portion of MVC? Or is it not the same thing. Is this combining the VC of MVC into one file?

Properties like .backgroundColor and .size are these the same thing as the @property and @synthesize and if so is this the same thing as an attribute? Meaning can properties and attributes be interchangeable terms in Objective-C or are they different? For example does .backgroundColor have the @properties syntax in some Cocoa class or is this the wrong way to look at it?

+4  A: 

Yes. An Objective-C class with the name "ViewController" in it's name is an Apple convention which indicates that it is a part of the 'Controller' portion according to the Model-View-Controller paradigm.

  • Model: Your data class.
  • View: NSView, NSImageView, etc.
  • Controller: NSViewController class.

    .backgroundColor and .size are both properties.

  • The @property keyword is the declaration keyword for a property.
  • The @synthesize keyword is required to instantiate the property.
Brock Woolf
Thanks Brock nice way to look at it!
I00I
+1  A: 

Your NSViewController subclass is definitely the controller in MVC. It controls the view and pushes data from your model classes into it.

You are also correct about .backgroundColor and all other dot-notation properties on built-in Cocoa classes. They are defined with @property and @synthesize just like classes you would write. However, there are more simple classes (actually, they are structs) used within Cocoa (such as NSSize and NSRange). When you access those fields with dot-notation (such as range.length, assuming range is an NSRange), they are not using @property or @synthesize since they are not actually Objective-C classes at all, but simple C structs.

I personally use "attribute" and "property" simultaneously in Objective-C, although other developers may disagree.

Marc W
Thanks Marc this terminology sometimes gets me doubting myself. I appreciate it!
I00I
No problem! Since this answer helped you, you can mark it as the "accepted" answer by clicking the green checkmark. That way other people will know you found it helpful. Welcome to StackOverflow!
Marc W