何の記事?
iOSでAzure Storageとデータをやり取りするための紐付け方法です。
操作がやや煩雑なので、次するときのための備忘録です。
開発環境
XCode 12.5
方法
Azureの公式ドキュメントに従ってやります。
https://github.com/Azure/azure-storage-ios
Cocoa Podsのインストール
ターミナルを起動して以下を入力していきます。
1 ruby gemを最新にする
sudo gem update --system
2 Cocoapodsのインストール
Cocoapodsは、swiftからObjectCのライブラリを使用するためのツールだそうです。
sudo gem install cocoapods
3 Cocoapodsのセットアップ
pod setup
これで準備ができました!
Pod fileの作成
1 Xcodeのプロジェクトファイルがあるフォルダのパスをコピー
2 ターミナル上で該当するフォルダに移動
cd /Users/***/Xcode/CorneaApp3
3 ポッドファイルを作成
pod init
4 ファイルの中身を確認
vi Podfile
こんな感じで表示されます。
iを押すと編集モードになります。(後にXCode上で編集しても可)
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'CorneaApp3' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for CorneaAppp3
end
5 公式ドキュメントに従ってpodfileを書き換える
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'CorneaApp3' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for CorneaApp3
pod 'AZSClient'
end
入力が終わったら「esc」で編集モード終了。
「:wq」で保存。
7 ライブラリのインストール
pod install
8 念の為アップデート
pod update
Bridging-Header.hファイルの作成
プロジェクトファイルの直下で、New File> Header Fileとして、ヘッダーファイルを作成。Bridging-Header.hと名前を付けます。
Bridging-Header.hに、以下の内容を書き込みます。
// Include the following import statement to use blob APIs.
# import <AZSClient/AZSClient.h>
プロジェクトファイルのBuild Settingsから、Swift Compiler-Generalの項目を探します。上のタブをAllにしないと出てこないので注意。
"Objective-C Bridging Header"という項目の横をクリックして、Bridging-Header.hと書き込みます。
最後に
これで設定は終わりです。読み書きのサンプルコードは公式のドキュメントをご参照下さい。