jdg / MBProgressHUD

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

Cannot find method `(nullable MBProgressHUD *)HUDForView:(UIView *)view` in Swift 3 #450

Closed sabirvirtuoso closed 6 years ago

sabirvirtuoso commented 7 years ago

Hi,

I found this Objective C API in MBProgressHUD.h but when I try to use it from Swift, the compiler throws an error. Any suggestions how I can access it from Swift or possible reasons why the API is not accessible from Swift.

Thanks

brightsider commented 7 years ago

In Swift 3 this is next function: /**

sabirvirtuoso commented 7 years ago

Thanks. I was just curious to know how the objective C header is bridged to Swift as it seems almost impossible for me to guess how it converts the above static function in Objective C to an optional initializer.

Regards.

merkury commented 5 years ago

the function is not exported to swift (4.2): + (nullable MBProgressHUD *)HUDForView:(UIView *)view;

If renamed to i.e. "findHUDForView" it is accessible from swift by: MBProgressHUD.find(for: myViewParam)

Instead of renaming you can add the following (new line!) after the definition in the header file:

+ (nullable MBProgressHUD *)HUDForView:(UIView *)view NS_SWIFT_NAME(find(for:));

With this "annotation" the method can be called from swift 4.2 with: MBProgressHUD.find(for: myViewParam)

merkury commented 5 years ago

As I said: HUDForView is not a constructor but a lookup method, that searches a HUD in all subviews. Please think about fixing this, as we still need this method.