我的代码在 Xcode 6.2 中运行良好。更新到 Xcode 6.3 后,我遇到了一些可空性错误。
我下载了 Parse SDK 1.7.1 后就解决了这些错误。所以我删除了项目中的旧 Parse 框架文件并将新的粘贴到其中。另外,我将我的代码转换为最新的 swift 语法“编辑/转换/最新的 swift 语法”。现在我没有 Nullabilty Errors 的问题,但还有其他几个问题。 在我的项目中,我有一个简单的 Tableviewcontroller,其代码如下:
import UIKit
class HaendlerTableViewController: PFQueryTableViewController {
// Initialise the PFQueryTable tableview
override init!(style: UITableViewStyle, className: String!) { //1. Falialbe initialize init/style:className:)' cannot override a non-failable initializer
super.init(style: style, className: className)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// Configure the PFQueryTableView
self.parseClassName = "Haendler"
self.textKey = "name"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}
// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery! { //2. Ovverriding method with selector queryForTable has incompatitble typ () -> PFQuery
var query = PFQuery(className: "Haendler")
query.orderByAscending("name")
return query
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject) -> PFTableViewCell { //3. Ovverriding method with selector 'tableView:cellForRowAtindexPath:object:' has incompatible type '(UITableView, NSIndexPath, PFObject) -> PFTableViewCell
var cell = tableView.dequeueReusableCellWithIdentifier("HaendlerCell") as! HaendlerCell!
if cell == nil {
cell = HaendlerCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
}
// Extract values from the PFObject to display in the table cell
cell.haendlerName.text = object["name"] as! String!
var thumbnail = object["logo"] as! PFFile
var initialThumbnail = UIImage(named: "haendler")
cell.haendlerBild.image = initialThumbnail
cell.haendlerBild.file = thumbnail
cell.haendlerBild.loadInBackground()
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var detailScene = segue.destinationViewController as! HaendlerDetailViewController
// Pass the selected object to the destination view controller.
if let indexPath = self.tableView.indexPathForSelectedRow() {
let row = Int(indexPath.row)
detailScene.currentObject = objects[row] as? PFObject //4. Could not find an overload for 'subscript' that accepts the supplied agruments
}
}
}
我在代码右侧的注释中写下了错误并且 以下。
- Falialbe initialize init/style:className:)' 不能覆盖非失败初始化器
- 覆盖选择器 queryForTable 的方法具有不兼容的类型 () -> PFQuery
- Ovverriding 方法与选择器 'tableView:cellForRowAtindexPath:object:' 具有不兼容的类型 '(UITableView, NSIndexPath, PFObject) -> PFTableViewCell
- 找不到接受提供的参数的“下标”重载
当我从 Parse Quickstart 创建一个新的 Swift 项目并添加一个 Tableviewcontroller 时,我遇到了同样的错误。在我的旧项目中有一个 objective-C 桥接 header ,我删除了它,因为我有机会直接在我的 Swift 项目中添加 Parse SDK 1.7.1。
现在我需要帮助,因为我看不到我必须改变什么..
PS:很抱歉德语和英语的代码混合了,一旦项目再次运行我会调整它
最佳答案
我在大约 20 分钟前将 Xcode 更新到 6.3 时遇到了同样的问题。
对于您的第二个错误,删除“!”在“PFQuery”之后。所以它现在应该看起来像..
覆盖 func queryForTable() -> PFQuery {
这解决了我关于该特定错误的问题。
我从未像您在第一个错误中那样使用 init 方法,但请尝试删除它并查看您得到的结果。没有它,我的 PFQueryTableViewController 工作正常。
关于xcode - 解析 SDK 1.7.1 在 Xcode 6.3 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29620428/