简体   繁体   中英

Swift Editor Placeholder in source file

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
}

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

Try cmd + shift + k to clean the project and run your code again. This fixed the issue for me.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM