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

Swift issue with NYTPhotoViewerDataSource.indexOfPhoto #276

Open
sluramod opened this issue Dec 14, 2018 · 1 comment
Open

Swift issue with NYTPhotoViewerDataSource.indexOfPhoto #276

sluramod opened this issue Dec 14, 2018 · 1 comment

Comments

@sluramod
Copy link

NYTPhotoViewerDataSource has NS_ASSUME_NONNULL_BEGIN, and in definition of indexOfPhoto:(id <NYTPhoto>)photo, photo is assumed to be non null. However, property currentlyDisplayedPhoto in NYTPhotosViewController is declared as nullable and in NYTPhotosViewController::setCurrentlyDisplayedViewController there is the following call [self.dataSource indexOfPhoto:self.currentlyDisplayedPhoto], which sometimes calls indexOfPhoto with nil.

The problem is due to NS_ASSUME_NONNULL_BEGIN Swift translates indexOfPhoto delegate method to func index(of photo:NYTPhoto) -> Int, and there is no way to check for nil. The only workaround is to call some objc method that allows checking for nil.

I'm not sure if the project is still maintained, but hopefully it is and it would be nice if somebody could fix this issue.

@ZevEisenberg
Copy link
Contributor

I just encountered this as well. Here's an annoying workaround, but this should be fixed:

func index(of photo: NYTPhoto) -> Int {
    let optional = Optional(photo)
    return images.firstIndex { $0 === optional } ?? 0
}

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

2 participants