I am working on a new Swift application based on the old Obj-c application. I am currently working on delegates
This is what my obj-c code in the .h file looked like
@interface MyAppViewController : CustomViewController @property (nonatomic, weak) id<MyAppViewControllerDelegate> delegate; @end @protocol MyAppViewControllerDelegate <NSObject> - (void)myAppViewController:(MyAppViewController *)controller loggedInStudent: (MYStudent *)student; - (void)myAppViewControllerWantsSignUp:(MyAppViewController *)controller; @end
In SWIFT, I did:
class MyAppViewController: CustomViewController { var delegate: MyAppViewControllerDelegate? protocol MyAppViewControllerDelegate{ func myAppViewController(controller: MyAppViewController, loggedInStudent: MYStudent) func myAppViewControllerWantsSignUp(controller: MyAppViewController)
I read and studied this a lot, so I thought that I was doing it mostly correctly (completely new for fast, though ... like that)
I get this error though, Declaration is only valid in file scope "on protocol MyAppViewControllerDelegate { I assumed that it had something to do with declaring it inside the class, so I moved it, only now my code inside the class does not recognize the delegate variable, which I announced.
Any ideas?
source share