MBProgressHUD无法在swift中工作:无法导入和使用

Jun*_* Gu 12 ios mbprogresshud swift

我使用cocoapods安装MBProgressHUB和桥接头我不能这样做

 #import "MBProgressHUD.h"
Run Code Online (Sandbox Code Playgroud)

我换了

#import "MBProgressHUD/MBProgressHUD.h"
Run Code Online (Sandbox Code Playgroud)

导入是可以的,但我不能在swift代码中使用它?我做错了什么?我怎么解决这个问题?

JRG*_*per 26

试试这个:

1)use_frameworks!在您Podfile使用框架中指定(而不是静态库).

这是添加使用Swift编写的pod作为依赖项所必需的,如果您的应用程序是用Swift编写的,那么这是一个好主意.

2)做 pod install

这可以确保您的项目设置为实际使用上述内容.

3)添加#import <MBProgressHUD/MBProgressHUD.h>你的桥接标题(注意尖括号 - 而不是引号)和import MBProgressHUD需要使用它的Swift类.

那是,

MyApp-Bridging-Header.h:

#import <MBProgressHUD/MBProgressHUD.h>
// ... other imports ...
Run Code Online (Sandbox Code Playgroud)

这将Objective-C文件暴露给Swift.尖括号表示这实际上是导入框架.

MyViewController.swift:

import UIKit
import MBProgressHUD
// ... other imports...

class MyViewController: UIViewController {
  // ... yada yada...
}
Run Code Online (Sandbox Code Playgroud)

这实际上导入了视图控制器使用的依赖项.