Newbie question follows...
I am learning Objective C based OS X Cocoa app development. Most of the books and videos I have are for iOS, so I am converting some simple iOS code examples to OS X.
When I create a new OS X "Cocoa Application" project, with the "use Storyboards" box checked, the default ViewController.m in my newly created project does NOT have an @interface section. Is this expected?
A reply to my recent question Cocoa ViewController.m vs. Cocoa Touch ViewController.m indicates that another user's default ViewController.m DOES have an @interface section.
Currently, I am manually typing the @interface section for IBOutlets. Is that what others are doing? Or do I have some configuration issue?
I am using Xcode 6.3.2 on Yosemite.
Here is my default ViewController.m
//
// ViewController.m
// testME
//
// Created by ME on 6/19/15.
// Copyright (c) 2015 ME. All rights reserved.
//
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
@end
Typically the interface for a class (ViewController in your case) is in the header file (.h).
However some developers use the convention of putting a class extension at the top of implementation files as a way of "faking" private methods (which Objective C doesn't have.)
So you could see this in a .m file:
//The parenthesis here indicate a class extension.
@interface ViewController ()
//Only the ViewController class sees this method.
-(void) method;
@end
@implementation ViewController
-(void) method{
//Do stuff here
}
@end
This is not specific to iOS or MacOS but rather Objective C. You can see more about Objective C class extensions here.
The default Xcode project does not add a class extension for the created ViewController class. However if you create a new NSViewController subclass (by going to File->New->File->Cocoa Class, then create a class that is a subclass of NSViewController, you will notice the new NSViewController subclass will have a class extension generated at the top of the implementation file. This however is not required or necessary, just used as a way of defining the closest thing Objective C allows to a private interface.
You can also check out this answer for more details about implementing psuedo-private methods.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다