2015-07-26 23 views
6

ben XCode 6 bir uygulama oluşturdu Bugün XCode 7 indirilen ve Swift 2 benim app güncellenen vardı hataların bir sürü vardı, ama şimdi sadece bir tane olduğunu.. . Ben neden bilmiyorum çözemez, ancak Xcodeanimated için herhangi Bool seçeneğine sahip olmak ve bu hata vermiyor -Swift 2: "Bool' dönüştürülebilen değil 'BooleanLiteralConvertible'

'Bool' 'BooleanLiteralConvertible'

dönüştürülebilir değil

(eğer Eğer animated için tam Bool sürdüğünü, sen

bilen var mı , nasıl çözebilir

var startVC = self.viewControllerAtIndex(indexImage) as ContentViewController 
var viewControllers = NSArray(object: startVC) 

self.pageViewContorller.setViewControllers(viewControllers as [AnyObject], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil) 
    'Bool' is not convertible to 'BooleanLiteralConvertible' 
), göreceksiniz fonksiyonu kendisine bakmak?

Teşekkürler.

+0

bunu yapacaklardır: okunabilir versiyonu olan

let startVC = viewControllerAtIndex(indexImage) let viewControllers = [startVC] pageViewController.setViewControllers(viewControllers, direction: .Forward, animated: true, completion: nil) 

yazım hatası "pageViewContorller"? – Renzo

cevap

12

Swift karışık ve yanlış bir hata mesajı veriyor. Sorun ilk parametre türü [UIViewController]? ait olduğunu, bu nedenle aşağıdaki çalışması gerekir:

self.pageViewContorller.setViewControllers(viewControllers as? [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil) 

Hatta daha da iyisi o zaman hiçbir döküm çağrısında gereklidir tip [UIViewController] olması için viewControllers beyan:

let viewControllers:[UIViewController] = [startVC] 
self.pageViewContorller.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil) 
+0

Teşekkürler, mükemmel çalışıyor! –

1

Mümkünse dökümden kaçınmaya çalışın. tip viewControllers ait [AnyObject][UIViewController]? uymuyor çünkü

func setViewControllers(_ viewControllers: [AnyObject]!, 
      direction direction: UIPageViewControllerNavigationDirection, 
      animated animated: Bool, 
     completion completion: ((Bool) -> Void)!) 

Swift 2

func setViewControllers(viewControllers: [UIViewController]?, 
      direction: UIPageViewControllerNavigationDirection, 
      animated: Bool, 
     completion: ((Bool) -> Void)?) 

böylece döküm karıştırır için: - setViewControllers:direction:animated:completion: için Swift 1 declaration den değişti. Gelecekte denetlenecek daha fazla Objective-C API'leri bekliyoruz.

İlk düzeltme viewControllerAtIndex dönmek için bir UIViewController:

func viewControllerAtIndex(index: Int) -> UIViewController { 
    ... 
} 

sonra sadece Swift doğru türlerini anlaması bakalım:

let startVC: UIViewController = viewControllerAtIndex(indexImage) 

let viewControllers: [UIViewController] = 
    Array<UIViewController>(arrayLiteral: startVC) 

pageViewController.setViewControllers(viewControllers, 
    direction: UIPageViewControllerNavigationDirection.Forward, 
    animated: true, completion: nil)