2017-05-11 56 views
2

我有一個有幾個init方法的類,並且在添加一個新變量並因此添加一個新的init之後,我開始僅在遇到以下錯誤編譯運行單元測試(我可以編譯並沒有得到該錯誤運行我的應用程序):無法爲類型調用初始值設定項...僅在編譯測試時

Overloads for 'SearchedLocation' exist with these partially matching parameter lists: (invocation: NSInvocation?), (selector: Selector),() 

我的班級:

class SearchedLocation : NSObject, MKAnnotation { 
    let coordinate: CLLocationCoordinate2D 
    let address : String? 
    let neighborhood : String? 
    let city : String 
    let fullAddress : String? 
    let name : String? 

// .... 

init(coordinate: CLLocationCoordinate2D, address: String, neighborhood: String, city: String, fullAddress: String) { 
    self.coordinate = coordinate 
    self.address = address 
    self.neighborhood = neighborhood 
    self.city = city 
    self.fullAddress = fullAddress 
    self.name = "" 
} 

init(coordinate: CLLocationCoordinate2D, address: String, neighborhood: String, city: String, fullAddress: String, name: String?) { 
    self.coordinate = coordinate 
    self.address = address 
    self.neighborhood = neighborhood 
    self.city = city 
    self.fullAddress = fullAddress 

    if name != nil && !name!.isEmpty { 
     if self.fullAddress!.contains(name!) { 
      self.name = "" 
     } else { 
      self.name = name! 
     } 
    } else { 
     self.name = "" 
    } 
} 

而這正是我得到的錯誤:

let place = SearchedLocation(coordinate: (placemark?.coordinate)!, address: address, neighborhood: placemark!.subLocality!, city: placemark!.locality!, fullAddress: fullAddress) 

該代碼工作得很好(即使在運行測試時),直到我將最後一個init方法添加到類中。現在即使我評論它,我仍然會收到該錯誤。

任何人都知道它是什麼?

+0

你使用任何形式的版本控制的斯威夫特編譯器錯誤可以得到臭名昭著神祕;?絲絲,最細微的變化可以剔掉編譯我意識到,這可能註釋是沒有幫助,但在提醒的精神,你確定你不能撤消這個? –

+0

哈哈哈哈第二我認爲這可能是與Git的東西(是的,我使用它!)。試試看看是否編譯器只是喜怒無常.... –

回答

1

撤消我的更改後,我意識到我創建了一個名爲「SearchedLocation」的測試類,就像我的類一樣。所以這就是爲什麼我只在編譯運行測試時纔得到這個錯誤。

愚蠢的錯誤:(

相關問題