I want to write a simple example on how delegates work in Swift. I've set up a class, a protocol and another class which adheres to the protocol. However I'm getting on two different places the same error. I've created a simple swift command line tool in xcode and all my code is inside main.swift. The code has no real functionality except learning how delegates work.

Here are the error messages:

> 
> Consecutive declarations on a line must be separated by ';'  
> 
>  Insert ';'  
> 
>  Expected '(' in argument list of function declaration  
> 
>  Expected '{' in body of function declaration  
> 
>  Expected 'func' keyword in instance method declaration  
> 
>  Insert 'func '  
> 
>  Expected declaration  
> 
>  Invalid redeclaration of 'delegate()' *//or anything() in the other error*
> 
> 
> 

Here is the code:

```
class MainClass {

    var delegate: MyProtocol? = nil

    delegate.doAnything() //getting 1st error here
}

protocol MyProtocol {
    func doAnything()
}

class OtherClass: MyProtocol {

    let anything = MainClass()

    anything?.delegate = self //getting 2nd error here

    func doAnything() {
        print("text")
    }
}

```