Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
}
like image 310
Sina Hamzezadeh Avatar asked Nov 29 '22 09:11

Sina Hamzezadeh


2 Answers

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.

Image

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

like image 109
ntoonio Avatar answered Dec 05 '22 13:12

ntoonio


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

like image 27
Techie Avatar answered Dec 05 '22 13:12

Techie