大佬教程收集整理的这篇文章主要介绍了ios – 文件范围? Swift代表和协议,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@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
在SWIFT我做了:
class MyAppViewController: CustomViewController { var delegate: MyAppViewControllerDelegate? protocol MyAppViewControllerDelegate{ func myAppViewController(controller: MyAppViewController,loggedInstudent: MYstudent) func myAppViewControllerWantsSignUp(controller: MyAppViewController)
我已经做了很多阅读和研究,所以我认为我做的基本上是正确的(尽管很快,但是……)
我收到此错误,“声明仅在文件范围内有效”,协议MyAppViewControllerDelegate {
我认为这与在类中声明它有关,所以我把它移出来,只是现在我的代码中的代码不能识别我声明的委托变量.
有任何想法吗?
protocol MyAppViewControllerDelegate { func myAppViewController(controller: MyAppViewController,loggedInstudent: MYstudent) func myAppViewControllerWantsSignUp(controller: MyAppViewController) } class MyAppViewController: CustomViewController { var delegate: MyAppViewControllerDelegate? }
虽然,如果您遵循一个常见模式,其中拥有MyAppViewController的对象也是其委托,这可能会导致内存问题.你可以使用类输入来允许弱委托,如下所示:
protocol MyAppViewControllerDelegate : class { func myAppViewController(controller: MyAppViewController,loggedInstudent: MYstudent) func myAppViewControllerWantsSignUp(controller: MyAppViewController) } class MyAppViewController: CustomViewController { weak var delegate: MyAppViewControllerDelegate? }
以上是大佬教程为你收集整理的ios – 文件范围? Swift代表和协议全部内容,希望文章能够帮你解决ios – 文件范围? Swift代表和协议所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。