re: How do I create a UICollectionView with standard layout programmatically in Swift 4? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: It's been a while since I've done this. I'll try to help. 1) I haven't seen that syntax before, but its allowing you to set properties for initial...
 

Hi @recursivefaults thank you so much for such a detailed response! I really appreciate it 😀. Is there a more common or better syntax for creating a collection view than the one I mentioned here? How would you do it?

  let myCollectionView: UICollectionView = {}()
 

I think you're two choices are going to be a classic version and the on you used. The classic one would look like this.

let myCollectionView: UICollectionView = UICollectionView()

I'm assuming there aren't required parameters.

Generally speaking I don't use closures for things when I can make it more explicit otherwise. I find they read poorly and depending on the language and situation you have to know that the closure executes on a seperate thread or execution context.

I've not used the closure based way before, so I can't speak to its long term usefulness. My first reaction to it is that I'd probably not use it unless I was doing something very complex that wrapping it up a function wouldn't cover.

code of conduct - report abuse