我刚刚开始了一个新的Swift项目,我想使用不同的库.特别是,我想使用一个Obj-C库Realm.io.但是,我还想使用纯粹的Swift库,如Alamofire或Dollar.
我使用Cocoapods来管理我的依赖项.我使用最新版本(0.37.0)和新use_frameworks!标志.pod install随时都是成功的.
不幸的是,当我尝试构建我的项目时,我得到两个错误(对于我的主要目标):
Umbrella header Realm.h not found 从 module.modulemapCould not build Objective-C module Realm 从任何文件使用 import Realm其他进口工作正常.
我注意到以下内容:如果我删除纯Swift库use_frameworks,一切正常.我知道Cocoapods目前的这个问题.但是,Realm要求开发人员使用该标志应该不是问题.
这是我的Podfile:
platform :ios, '8.0'
use_frameworks!
target 'rothrock' do
pod 'Realm'
pod 'Cent'
pod 'SwiftyJSON'
pod 'Alamofire'
end
target 'rothrockTests', :exclusive => true do
end
Run Code Online (Sandbox Code Playgroud)
我没有使用桥接头.我是不是该?
任何想法或解决方法?
我试图注入一个自定义WebKit脚本消息处理程序.我的控制器已正确加载和视图.但是,在JS端(来自Safari控制台),window.webkit.messageHandlers是空的.知道为什么吗?我的应用程序使用的是iOS 8.1,但即使升级到9.2,也无效.
import Foundation
import UIKit
import WebKit
public class FooController: UIViewController, WKScriptMessageHandler {
private var wkWebView: WKWebView?
public override func viewDidLoad() {
super.viewDidLoad()
let o = WKUserContentController()
o.addScriptMessageHandler(self, name: "foo")
let config = WKWebViewConfiguration()
config.userContentController = o
self.wkWebView = WKWebView(frame: self.view.bounds, configuration: config)
self.view.addSubview(self.wkWebView!)
self.wkWebView!.loadRequest(NSURLRequest(URL: NSBundle.mainBundle().URLForResource("foo", withExtension: "html")!))
}
public func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
print("foo")
}
}
Run Code Online (Sandbox Code Playgroud) 这里我有两个 JS 异步函数同时运行。
当一个结束时(回调已经运行),我想阻止另一个继续。但是(这是我的问题)我不能使用 global vars。然后,我想知道是否可以停止 JS 中的挂起函数或以任何方式解决我的问题。
我将不胜感激任何答案:)
编辑:
一些澄清:
关于代码,这是我想要生成的示例:
asyncFirst(
// ... args
function() { // callback
console.log('foo');
stopOther();
}
);
asyncSecond(
// ... args
function() { // callback
console.log('bar');
stopOther();
}
);
asyncFirst(...);
asyncSecond(...);
Run Code Online (Sandbox Code Playgroud)
不使用“状态”变量的 stopOther() 算法是什么?
ios ×2
swift ×2
asynchronous ×1
cocoapods ×1
javascript ×1
objective-c ×1
realm ×1
wkwebview ×1