源文件中的Swift Editor占位符

时间:2016-12-19 12:38:25

标签: ios swift placeholder

嗨有快速错误“源文件中的Swift编辑器占位符”的问题 这是我的代码

public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: <#T##IndexPath#>) as! CustomBrandCell

    let brandImage: UIImage = UIImage(named: self.brands[indexPath.row].name)!

    cell.brandImageView.image = brandImage

    return cell
}

3 个答案:

答案 0 :(得分:14)

我在SO上多次发现同样的问题。但他们都没有给出我想要的答案。

如果您的代码中有其中一个(其中带有蓝色背景的“字符串”),则会获得Placeholder in source file

Image

占位符适合我们的程序员。它说“这里应该是String类型的值”。您可以单击它并开始键入,只需将其替换为例如变量名称即可。您也可以按Tab键自动选择下一个占位符。当您调用具有多个参数的函数(因此调用多个占位符)时,这非常有用。

占位符实际上只是普通文本(&lt;#T ## Strign#&gt;),但XCode“翻译”它看起来就像它一样。

在您的情况下,错误在第三行。

...withReuseIdentifier: "Cell", for: <#T##IndexPath#>) as! CustomBrandCell

正如您所看到的,<#T##IndexPath#>是一个占位符,就像我之前提到的普通文本一样。您可能希望这是indexPath

答案 1 :(得分:3)

尝试使用cmd + shift + k清理项目,然后再次运行代码。这为我解决了这个问题。

答案 2 :(得分:0)

试试这个。希望能解决你的问题

public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{

      // get a reference to your storyboard cell
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath as IndexPath) as! CustomBrandCell

     let brandImage: UIImage = UIImage(named: self.brands[indexPath.row].name)!

     cell.brandImageView.image = brandImage

     return cell
}
相关问题