ios 源文件中的 Swift 编辑器占位符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41222786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swift Editor Placeholder in source file
提问by Sina Hamzezadeh
hi have problem with the swift error "Swift Editor Placeholder In Source File" This is my code
嗨,快速错误“源文件中的 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
}
回答by ntoonio
I found the same question many times on SO. But none of them gave the answer I was looking for.
我在 SO 上多次发现相同的问题。但他们都没有给出我正在寻找的答案。
You get the Placeholder in source file
when you have one of these (where it says "String" with a blue background) in your code.
你得到的Placeholder in source file
,当你有其中之一(它说:“串”用蓝色背景)在你的代码。
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).
占位符是给我们程序员的。它说“这里应该是一个字符串类型的值”。您可以单击它并开始输入,只需将其替换为例如变量名称。您也可以按 Tab 键自动选择下一个占位符。当您调用具有多个参数(因此具有多个占位符)的函数时,这非常有用。
A placeholder is actually just normal text (<#T##Strign#>), but XCode "translates" it to look like how it does.
占位符实际上只是普通文本 (<#T##Strign#>),但 XCode 将其“翻译”成它的样子。
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
如您所见<#T##IndexPath#>
,占位符与我之前提到的普通文本一样。你可能希望这是indexPath
回答by Museer Ahamad Ansari
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
}
回答by Techie
Try cmd + shift + k to clean the project and run your code again. This fixed the issue for me.
尝试 cmd + shift + k 清理项目并再次运行您的代码。这为我解决了这个问题。