我需要帮助将这个Objective-C方法重写为Swift。
目标代码:
- (void)pushViewControllerAnimatedWithMember:(Member *)member withSelf:(id)controller
{
ZJMHomePageViewController *homePageViewController = [ZJMHomePageViewController new];
homePageViewController.member = member;
homePageViewController.delegate = controller;
[self.navigationController pushViewController:homePageViewController animated:YES];
}
SwiftCode :
func pushViewControllerAnimatedWithMember(member: Member, withSelf controller: AnyObject?)
{
let homePageViewController : ZJMHomePageViewController = ZJMHomePageViewController.new()
homePageViewController.member = member
homePageViewController.delegate = controller // gives error as Not able to assign any object to delegate
self.navigationController?.pushViewController(homePageViewController,animated:true)
}
答案 0 :(得分:0)
委托属性类型必须是AnyObject,因此您可以将其传递好。基本上,控制器和委托必须是相同的类型,或者在分配它的值时需要添加强制转换(as)