jdg / MBProgressHUD

MBProgressHUD + Customizations
http://www.bukovinski.com/
MIT License
16.01k stars 3.56k forks source link

Could not build on Xcode 15 #640

Closed aaa-1902 closed 1 year ago

aaa-1902 commented 1 year ago

There is an issue with this [(id)indicator setProgress:progress]
and shows a "Multiple methods named 'setProgress:' found with mismatched result, parameter type or attributes" error

This was from a manually imported library and not through pods so I'm not quite sure how outdated this is.

- (void)updateUIForKeypath:(NSString *)keyPath {
    if ([keyPath isEqualToString:@"mode"] || [keyPath isEqualToString:@"customView"]) {
        [self updateIndicators];
    } else if ([keyPath isEqualToString:@"labelText"]) {
        label.text = self.labelText;
    } else if ([keyPath isEqualToString:@"labelFont"]) {
        label.font = self.labelFont;
    } else if ([keyPath isEqualToString:@"detailsLabelText"]) {
        detailsLabel.text = self.detailsLabelText;
    } else if ([keyPath isEqualToString:@"detailsLabelFont"]) {
        detailsLabel.font = self.detailsLabelFont;
    } else if ([keyPath isEqualToString:@"progress"]) {
        if ([indicator respondsToSelector:@selector(setProgress:)]) {
            [(id)indicator setProgress:progress];
        }
        return;
    }
    [self setNeedsLayout];
    [self setNeedsDisplay];
}
nikit6000 commented 1 year ago

This problem can be solved using a special protocol that allows you to set progress.

Firstly, create the protocol MBProgressHUDProgressRepresentable in MBProgressHUD.h

@protocol MBProgressHUDProgressRepresentable <NSObject>
- (void)setProgress:(float)progress;
@end

Then, extend the MBRoundProgressView to conforms MBProgressHUDProgressRepresentable

/**
 * A progress view for showing definite progress by filling up a circle (pie chart).
 */
@interface MBRoundProgressView : UIView <MBProgressHUDProgressRepresentable>

Note: MBRoundProgressView already has implementation for setProgress: method

At the next step you need to forward MBProgressHUDProgressRepresentable just like MBProgressHUDDelegate

@protocol MBProgressHUDDelegate;
@protocol MBProgressHUDProgressRepresentable;  // <-- line to be added under @protocol MBProgressHUDDelegate;

And finaly replace this

if ([indicator respondsToSelector:@selector(setProgress:)]) {
    [(id)indicator setProgress:progress];
}

by this:

if ([indicator conformsToProtocol:@protocol(MBProgressHUDProgressRepresentable)]) {
    [(id<MBProgressHUDProgressRepresentable>)indicator setProgress: progress];
}

Note: if you are using customView as indicator you need to conform customView class to MBProgressHUDProgressRepresentable