Swift Editor Placeholder in source file

时间秒杀一切 提交于 2020-01-08 18:01:18

问题


hi have problem with the swift error "Swift Editor Placeholder In Source File" This is my code

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
}

回答1:


I found the same question many times on SO. But none of them gave the answer I was looking for.

You get the Placeholder in source file when you have one of these (where it says "String" with a blue background) in your code.

A placeholder is for us programmers. It says "here should be a value of the type String". You can click on it and start typing, to simply replace it with for example a variable name. You can also press tab to automatically select the next placeholder. This is very useful when you are calling a function with multiple parameters (and therefore multiple placeholders).

A placeholder is actually just normal text (<#T##Strign#>), but XCode "translates" it to look like how it does.

In your case the error is on line three.

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

As you can see <#T##IndexPath#> is a placeholder as normal text as I mentioned earlier. You probably want this to be indexPath




回答2:


Try this. hope solve your problem

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
}


来源:https://stackoverflow.com/questions/41222786/swift-editor-placeholder-in-source-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!