Objective-C protocol in Swift - display does not match error

I am trying to use the Objective-C library (MWPhotoBrowser) in my Swift application. My Swift class conforms to the MWPhotoBrowserDelegate protocol, using the necessary methods. However, I keep getting the following error:

"Type" PhotoLibrary "does not comply with the protocol" MWPhotoBrowserDelegate "

Protocols

Cocoa are working fine. Has anyone encountered this problem before?

Here is a sample code:

class PhotoLibrary: UIImageView, MWPhotoBrowserDelegate {

    init() {
        super.init(frame: CGRectZero)
    }

    func numberOfPhotosInPhotoBrowser(photoBrowser: MWPhotoBrowser!) -> Int {
        return 0
    }

    func photoBrowser(photoBrowser: MWPhotoBrowser!, photoAtIndex index: Int) -> MWPhoto! {
        return nil
    }
}

The definition of the protocol is as follows:

@protocol MWPhotoBrowserDelegate <NSObject>

- (NSInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser;
- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSInteger)index;

@optional

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index;
- (MWCaptionView *)photoBrowser:(MWPhotoBrowser *)photoBrowser captionViewForPhotoAtIndex:(NSUInteger)index;
- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index;
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index;
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index;
- (BOOL)photoBrowser:(MWPhotoBrowser *)photoBrowser isPhotoSelectedAtIndex:(NSUInteger)index;
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index selectedChanged:(BOOL)selected;
- (void)photoBrowserDidFinishModalPresentation:(MWPhotoBrowser *)photoBrowser;

@end
+4
source share
4 answers

Here is what I understood:

Swift id. MWPhotoBrowser, id (MWPhoto *). , MWPhoto * .

.

+2

MWPhotoBrowser, Swift , MWPhotoBrowser.

func showFullScreenImage(image:UIImage) {
    let photo:MWPhoto = MWPhoto(image:image)

    self.photos = [photo]

    let browser:MWPhotoBrowser = MWPhotoBrowser(delegate: self)

    browser.displayActionButton = true
    browser.displayNavArrows = false
    browser.displaySelectionButtons = false
    browser.zoomPhotosToFill = true
    browser.alwaysShowControls = false
    browser.enableGrid = false
    browser.startOnGrid = false
    browser.enableSwipeToDismiss = true

    browser.setCurrentPhotoIndex(0)

    self.navigationController?.pushViewController(browser, animated: true)
}

func numberOfPhotosInPhotoBrowser(photoBrowser: MWPhotoBrowser!) -> UInt {
    return UInt(self.photos.count)
}

func photoBrowser(photoBrowser: MWPhotoBrowser!, photoAtIndex index: UInt) -> MWPhotoProtocol! {
    if Int(index) < self.photos.count {
        return photos.objectAtIndex(Int(index)) as! MWPhoto
    }
    return nil
}

func photoBrowserDidFinishModalPresentation(photoBrowser:MWPhotoBrowser) {
    self.dismissViewControllerAnimated(true, completion:nil)
}

var, . private var photos = [] Bridging-Header.h:

#import <MWPhotoBrowser/MWPhoto.h>
#import <MWPhotoBrowser/MWPhotoBrowser.h>

https://github.com/mwaterfall/MWPhotoBrowser/issues/325#issuecomment-64781477.

+4

xCode 7.1 - , .

  • Cocoa Pods.

  • :

    #import <MWPhotoBrowser/MWPhoto.h>

    #import <MWPhotoBrowser/MWPhotoBrowser.h>

  • → "Pods" ( )

  • → add: libMWPhotoBroswer, MediaPlayer.framework, libSDWebImage, libMBProgressHUD libDACIrcularProgress ( ', x86_64')

  • → add '-ObjC' ( SDWebImage framework)

, -.

0

swift 3.0, :

(1) MWPhotoBrowser.h / "id <MWPhoto>" "MWPhoto *"

(2) :

public func numberOfPhotos(in photoBrowser: MWPhotoBrowser!) -> UInt {
    return UInt(arrPhotos.count)
}

public func photoBrowser(_ photoBrowser: MWPhotoBrowser!, photoAt index: UInt) -> MWPhoto! {
    return arrPhotos[Int(index)] as MWPhoto
}
0

All Articles