2015-07-02 22 views
5
func testExample() { 
    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 
    // some code ... 
} 

yukarıdaki fonksiyon daima çökmesine ederken AppDelegate erişebilir ve bu hata veriyor Can not: test hedef halinetest Xcode projesinde

Could not cast value of type 'MyAppName.AppDelegate' (0x10dc09e80) to 'MyAppNameTests.AppDelegate' (0x11cc190c0).

cevap

1

Muhtemelen AppDelegate topluyorlar. Bunu yapma. Bunun yerine, yalnızca normal uygulama hedef MyAppName'inizde derleyin. Eğer 7

@testable import MyAppName 

ve XCode 7

import MyAppName 
benim test sınıfında "@testable ithalat MyAppName" yazılı
+0

bana bu hata veriyor önce XCode sınıf yazma testi ise: Bilinmeyen özellik 'test edilebilir' – Mohammed

+0

Sonra don XCode 7'yi kullanmayın. XCode 7'den önce '@testable' öğesini kaldırın. –

+0

o işe yaramadı, – Mohammed

İlgili konular