gpt4 book ai didi

在 RxSwift 中快速使用未解析的标识符 `create`

转载 作者:搜寻专家 更新时间:2023-11-01 06:37:53 24 4
gpt4 key购买 nike

我开始学习 Swift 并且我正在实现一个 Observable(使用 RxSwift)以在 OSX 应用程序中通过 AlamoFire 简化网络调用。

导入:

import RxSwift
import RxCocoa
import Alamofire

方法:

下面的创建标识符正在报告:使用未解析的标识符 create

func getAPI(body: String) -> Observable<AnyObject?> {
return create { observer in
let request = AlamoFireXMLPostRequest(body)
.responseData(completionHandler: { request, response, data, error in
if ((error) != nil) {
observer.on(.Error(error!))
} else {
observer.on(.Next(getXMLfromFreshbooksResponse(response)))
observer.on(.Completed)
}
})
return AnonymousDisposable {
request.cancel()
}
}
}

CocoaPods:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# Needed by SWXMLHash
source 'https://github.com/CocoaPods/Specs.git'
platform :osx, '10.10'

target 'Tractor Beam' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for Tractor Beam
pod 'Alamofire', '~> 3.4'

# Convert HTTP AF Responses to XML
pod 'AlamofireXmlToObjects'
pod 'SWXMLHash', '~> 2.5.0'

# Rx
pod 'RxSwift', '~> 2.6.0'
pod 'RxCocoa', '~> 2.6.0'

target 'Tractor BeamTests' do
inherit! :search_paths
# Pods for testing
end

target 'Tractor BeamUITests' do
inherit! :search_paths
# Pods for testing
end

end

#post_install do |installer|
# installer.pods_project.targets.each do |target|
# target.build_configurations.each do |config|
# config.build_settings['SWIFT_VERSION'] = '3.0'
# config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.10'
# end
# end
#end

最佳答案

createObservable 类的静态方法。因此,您需要通过以下方式调用它,例如:Observable.create...

此外,您应该避免无故使用 ! 运算符。例如:

if ((error) != nil) {
observer.on(.Error(error!))
}

应该写成:

if let error = error {
observe.on(.Error(error))
}

关于在 RxSwift 中快速使用未解析的标识符 `create`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39335889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com