古いプロジェクトでの最小限度の対応
事前準備
Podでそのまま使おうとするとこんなエラーが出る
SDK does not contain 'libarclite' at the path
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphoneos.a';
try increasing the minimum deployment target
Xcode 14.3から、古いOS向けの「ARC(Automatic Reference Counting)」をサポートするためのライブラリ(libarclite)が同梱されなくなりました。
プロジェクトや利用しているライブラリ(CocoaPodsなど)の「最小サポートOS」が iOS 11.0未満に設定されていると、Xcodeはこのライブラリを探しに行きますが、ファイルが存在しないためエラーになります。
対策
Podfileに記述
post_install do |installer|
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
# iOS 11.0未満のものを一括で11.0に引き上げる
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
end
end
end
end
pod install 後にエラー解消
MBProgressHUD拡張
せっかくなので rx で拡張も
import UIKit
import MBProgressHUD
import RxSwift
import RxCocoa
extension Reactive where Base: MBProgressHUD {
static func isAnimating(view: UIView) -> AnyObserver<Bool> {
return AnyObserver { event in
switch event {
case .next(let value):
if value {
MBProgressHUD
.showAdded(to: view, animated: true)
} else {
MBProgressHUD
.hide(for: view, animated: true)
}
default:
break
}
}
}
}
こんなふうにして使う
// 検索中はMBProgressHUDを表示
self.viewModel.outputs.isLoading.asDriver(onErrorJustReturn: false)
.drive(MBProgressHUD.rx.isAnimating(view: self.view))
.disposed(by: disposeBag)