Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access datasource object property from didSelectItemAt ? #5

Closed
jesus-rod opened this issue Mar 24, 2017 · 1 comment
Closed

Comments

@jesus-rod
Copy link

jesus-rod commented Mar 24, 2017

from my method

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)

I can print the object like so

let object =  self.datasource?.objects?[indexPath.item]
print(object)

but if I want to access a property from my object, I can't. For instance,

print(object.imageUrl)

does not work.

How to go about this?

I've used the demo project to play with the library and the class I am trying to access is very similar to the Intermediate Example

struct MenuItem {
    let name: String
    let imageUrl: String
    let destination: String
```
    
```
    init(name: String, imageUrl: String, destination: String = "none"){
        self.name = name
        self.imageUrl = imageUrl
        self.destination = destination.uppercased()
    }
}`
```

@jesus-rod
Copy link
Author

Well, this was pretty obvious but I had forgotten this since working with Genome.

I just had to cast it to my class

let object = self.datasource?.objects?[indexPath.item] as? MenuItem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant