Xcode 错误 "value of type '[UIViewController]' has no member 'firstObject'"
Xcode error "value of type '[UIViewController]' has no member 'firstObject'"
我正在尝试创建 this GitHub repository 的 Swift 版本。我首先将所有代码从 Objective-C 直接转移到 Swift,这导致了很多错误(321 行文件中有 60 个错误)。
对于这行特定的代码
self.currentViewController = self.childViewControllers.firstObject
我收到这个错误:
Value of type '[UIViewController]' has no member 'firstObject'
我尝试添加 as! UIViewController
,并在可能的大多数位置放置感叹号和问号。 None 我从建议的帖子中尝试的事情有所帮助。
它只是在 Swift 个数组上调用 first
。
self.currentViewController = self.childViewControllers.first
我正在尝试创建 this GitHub repository 的 Swift 版本。我首先将所有代码从 Objective-C 直接转移到 Swift,这导致了很多错误(321 行文件中有 60 个错误)。
对于这行特定的代码
self.currentViewController = self.childViewControllers.firstObject
我收到这个错误:
Value of type '[UIViewController]' has no member 'firstObject'
我尝试添加 as! UIViewController
,并在可能的大多数位置放置感叹号和问号。 None 我从建议的帖子中尝试的事情有所帮助。
它只是在 Swift 个数组上调用 first
。
self.currentViewController = self.childViewControllers.first