Swift issue with NYTPhotoViewerDataSource.indexOfPhoto
sluramod opened this issue · comments
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.
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
}