xcode 定义与 Swift 2.0 中的先前值冲突
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32647438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Definition conflicts with previous value in Swift 2.0
提问by Alexander Khitev
I updated Xcode to version 7 and Swift 2.0. My application works and there are not any errors in Xcode 6 with Swift 1.2. I now get the error "Definition conflicts with previous value" in method func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
and I see Previous definition of 'tableView
' is here
我将 Xcode 更新到版本 7 和 Swift 2.0。我的应用程序工作正常,在 Xcode 6 和 Swift 1.2 中没有任何错误。我现在在方法中收到错误“定义与先前值冲突”,func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
并且我看到“先前的定义tableView
”在这里
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if searchPredicate == nil {
return arrayItem.count ?? 0
} else {
return arrayFilterOfNames.count ?? 0
}
}
Error is here
错误在这里
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("artistTwo", forIndexPath: indexPath) as! SongsCellArtist
if searchPredicate == nil {
var currentString = arrayItem[indexPath.row]
var urlULTRA: NSURL!
var ultraDirectory = fileManager.URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask)
if var ultraURL: NSURL = ultraDirectory.first as? NSURL {
urlULTRA = ultraURL.URLByAppendingPathComponent(currentString)
}
var ultraMediaPlayer = AVPlayerItem(URL: urlULTRA)
var ultraCommonMetaData = ultraMediaPlayer.asset.commonMetadata
for ultraData in ultraCommonMetaData {
if ultraData.commonKey == "title" {
// println("ultra data equals \(ultraData.stringValue)")
nameSongForPass = ultraData.stringValue
}
if ultraData.commonKey == "artist" {
nameArtistForPass = ultraData.stringValue
}
if ultraData.commonKey == "album" {
nameAlbumForPass = ultraData.stringValue
}
if ultraData.commonKey == "artwork" {
imageSongForPass = ultraData.dataValue
}
}
cell.nameSong?.text = nameSongForPass
if nameAlbumForPass != nil {
cell.artistAlbumName?.text = "\(nameArtistForPass) - \(nameAlbumForPass)"
} else {
cell.artistAlbumName?.text = "\(nameArtistForPass)"
}
if imageSongForPass != nil {
cell.imageSongs?.image = UIImage(data: imageSongForPass)
} else {
cell.imageSongs?.image = UIImage(named: "Notes100.png")
}
} else {
var name: String! = arrayFilterOfNames[indexPath.row]
cell.nameSong.text = name
}
return cell
}
回答by
This is definitely the "{}" issue.Please check you correctly closed the curly bracket.
这绝对是“{}”问题。请检查您是否正确关闭了大括号。
回答by vadian
The return value of tableView:cellForRowAtIndexPath
is declared as optional
的返回值tableView:cellForRowAtIndexPath
声明为可选
... -> UITableViewCell?
Edit:Actually it depends on the Swift version.
Meanwhile the signature of cellForRowAtIndexPath
has changed to the non-optional return type.
编辑:实际上这取决于 Swift 版本。
同时签名cellForRowAtIndexPath
已更改为非可选返回类型。
回答by Naishta
Check the tableview delegate functions are outside of Viewdidload
, and that the table delegates and datasources are correctly set.
检查 tableview delegate functions are outside of Viewdidload
,并正确设置表委托和数据源。
For me, I had the functions withing viewdidload, taking it out and building again worked in Swift 2.2
对我来说,我在 Swift 2.2 中使用了 viewdidload 的功能,将其取出并再次构建
回答by JSBach
For it was using the same parameter name twice in the signature.
因为它在签名中两次使用相同的参数名称。
回答by Honey
I was getting the same error because I was doing something like:
我遇到了同样的错误,因为我正在做类似的事情:
func doSomething (param1: String, param1: String){
print(param1)
print(param1)
}
This was because both my arguments are param1
! I actually wanted to write param
and param2
.
这是因为我的两个论点都是param1
! 我实际上想写param
和param2
。
Learned it the hard way!
艰难地学会了!
回答by Adam
Change the declaration to:
将声明更改为:
override func tableView(tv: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {}
or change your property name.
或更改您的物业名称。