最新のXcodeを更新して以来、このコードに関連して「下付き文字のあいまいな使用」が発生しました。下付きスウィフトiOSのあいまいな使用
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("postsCell") as! CustomTableViewCell!
if cell == nil {
cell = CustomTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "postsCell")
}
let dict:NSDictionary = arrPosts[indexPath.row]
if let postResourceName = dict["resource_name"]![0] as! String? where !postResourceName.isEmpty {
cell?.customPostTitle?.text = String(htmlEncodedString: postResourceName)
} else if let postTitle = dict["title"]!["rendered"] as? String {
cell?.customPostTitle?.text = String(htmlEncodedString: postTitle)
}
特にこの行には、
if let postResourceName = dict["resource_name"]![0] as! String? where !postResourceName.isEmpty {
私はSwiftには新しく、これはエラーがスローされている理由である可変型に関する詳細の不足に関係していると思います。しかし、私はコードが何であるべきかについては不明です。
任意のポインタ?
よろしく、 マイケル
あいまいな使用は辞書からの値が常にあるので、コンパイラは適切な型を推測することができないことを意味し
'ANYOBJECTでを交換することにより、あなたの辞書に
Array
を持っていることを指定することができ'。 'arrPosts'はどのように宣言されていますか?そして、あなたがSwiftに慣れていないなら、言語ガイドの 'Optional binding'についてのパラグラフを注意深く読んでください。 – vadianarrPostsの初期変数は次のように定義されています。 var arrPosts = [[String:AnyObject]] –