Search code examples
xcodevmware-fusion

How to show necessary methods to be implemented for specific protocol


I am absolute beginner with IOS and XCode and swift and I am doing my first tries with Xcode in a Yosemite built in a Vmware running under Windows7 (guest is MAC yosemite, Host is windows running vmware workstation 9 )

I have a ViewController Class in my IOS project declared as follow:

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {...}

Now I would like to implement the necessary methods of the protocols UIViewController and UITableViewDelegate.

In a tutorial

http://jamesonquave.com/blog/developing-ios-apps-using-swift-tutorial/

it says I have to use Command+Click on a protocoll to show which methods should be implemented.

I don't know howto do "command+click on the protocoll" this with my vmware.

any hints ?

When using Alt+clicking on a protocoll it shows me the help. If I am WindowsButton+clicking on a protocoll it opens a new window with sourcecode of the protocoll. Now howto show methods, which should be implemented.


Solution

  • To help you out, UIViewController is a class, which you are subclassing. It is not a protocol, so it doesn't have any necessary methods for you to implement. You can however override the methods you inherit, which is what you see in when you first create the file, ex.

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
    

    This overrides the method you inherited from UIViewController. If you aren't doing anything other than calling super.viewDidLoad() you can remove the entire function from your code.

    Now UITableViewDataSource and UITableViewDelegate or both protocols, so they may or may not have required methods to implement.

    What you describe when you alt-click, is the same as if you right clicked on UITableViewDataSource and selected jump to definition. This is what you get when you command click on an actual Mac. What the tutorial is saying is that the required methods will be at the top, which isn't always the case if you look at the documentation (as the methods are organized more by purpose there). In the case of UITableViewDataSource, you should see something like:

    protocol UITableViewDataSource : NSObjectProtocol {
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    
    // Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
    // Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    
    optional func numberOfSectionsInTableView(tableView: UITableView) -> Int // Default is 1 if not implemented
    
    optional func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? // fixed font style. use custom view (UILabel) if you want something different
    optional func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String?
    

    You will notice that the first two methods func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int and func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell do not have optional in front of them. This means that these are the required methods for this protocol. The optional ones below that are optional.

    In the case of UITableViewDelegate you'll see that there are no non-optional methods, and therefore it does not require you to implement any.