iOS
Parse Swift SDK
iOS Swiftプロジェクト向けParse SDKのインストール方法
12 分
ios swiftプロジェクトにparse sdkをインストールする はじめに このセクションでは、parse swift ios sdkをxcodeプロジェクトにインストールする方法を学びます。 このチュートリアルでは、xcode 12で作成された基本的なアプリを使用します。 ios 14 です。 いつでも、このチュートリアルで構築された完全なプロジェクトにアクセスできます。 githubリポジトリ です。 前提条件 このチュートリアルを完了するには、次のものが必要です: back4appで作成されたアプリ。 注意: 新しいparseアプリのチュートリアル を参照して、back4appでアプリを作成する方法を学んでください。 xcode。 基本的なiosアプリ。 注意: 基本的なアプリが作成されていない場合は、xcodeを開いて、 ファイル > 新規 > プロジェクト > ios を選択します。次に、 アプリ を選択します。基本的なアプリを作成したら、このガイドに従う準備が整います。 1 インストール方法を選択してください swift package manager 1 1 parse swift sdkパッケージを追加 swift package manager まだparse ios sdkをインストールしていない場合は、この手順に従ってください。 新しいバージョンの xcode には、swift package manager が組み込まれています。これは、parse swift sdk をプロジェクトにインストールし、更新を維持する最も簡単で最良の方法です。 現在、この方法を使用してparse swift sdkをインストールすることをお勧めします。 ( ファイル ファイル )メニューから、( swiftパッケージ swiftパッケージ )を選択し、次に( パッケージ依存関係を追加 パッケージ依存関係を追加 ) ( パッケージリポジトリを選択 パッケージリポジトリを選択 )ウィンドウで、parse swift sdkのgithubウェブサイトのurl( https //github com/parse community/parse swift )を貼り付けて、 次へ 次へ をクリックします。 ( リポジトリ リポジトリ )ウィンドウでは、 バージョン バージョン , ブランチ ブランチ または特定の コミット コミット お好みの方法を選択し、 次へ 次へ 待ってください xcode xcode がすべての parse swift parse swift 依存関係を解決するのを待ってから、 次へ 次へ htパッケージ製品を確認してください parseswift parseswift がチェックされていて、ターゲットが正しく選択されていることを確認してください ターゲットに追加 ターゲットに追加 , 次に 次へ 次へ swiftパッケージは、プロジェクトのすぐ下にある依存関係ツリーに表示され、その右側にバージョンが表示されるべきです 更新が必要な場合は、 parseswift parseswift パッケージを依存関係ツリーの下で右クリックし、 パッケージを更新 パッケージを更新 を選択します。このプロセスは自動的にすべてを更新します。 おめでとうございます!parse swift ios sdkをインストールしました cocoapods 1 1 parse swift ios sdkをインストールする まだparse swift ios sdkをインストールしていない場合は、この手順に従ってください。 xcodeは cocoapods をswiftおよびobjective c cocoaプロジェクトの依存関係マネージャーとして使用できます。 参照できます cocoapods 入門ガイド 追加の詳細については。 cocoapodsをインストールするには、ターミナルを開き、以下のコードスニペットをコピーしてターミナルに貼り付け、リターンを押してください cocoapodsは、パスワードを入力した後に自動的にインストールされるはずです。問題がある場合は、ローカルのrubyのバージョンをアップグレードする必要があるかもしれません。 次に、xcodeプロジェクトフォルダーを開き、そのフォルダーでターミナルウィンドウを開きます。 今からpodfileを作成します。以下のコードスニペットをコピーして、ターミナルに貼り付けてリターンを押してください フォルダーにpodfileが表示されている場合、正しく行いました。 気をつけて、 ポッドファイルが見えない場合は、ターミナルが実際にプロジェクトフォルダー内にあることを確認してください 次に、xcodeまたは任意のテキストエディタでpodfileを開き、各ターゲットの下に「pod 'parse'」を追加します。 あなたのpodfileは次のようになります これからparse swiftをプロジェクトに追加します。ターミナルがプロジェクトフォルダーを開いていることを確認してください。以下のコードスニペットをコピーしてターミナルに貼り付け、リターンを押してください cocoapodsはプロジェクトをワークスペースとして再構築し、あなたのプロジェクトは今このように見えるようになります。 すでにxcodeプロジェクトを開いている場合は、それを閉じてください。これからはプロジェクトファイルの代わりにワークスペースファイルを開きます。ワークスペースファイルをダブルクリックして開いてください。 おめでとうございます!あなたは今、parse ios sdkをインストールしました 2 あなたのparseアプリを接続する プロジェクトのappdelegate swiftファイルを開いて、アプリの資格情報を設定します。 parse swift ios sdkは、これらの設定を使用してback4appサーバーに接続します。 ファイルの先頭に「didfinishlaunchingwithoptions」という関数が表示されるはずです。 この関数内に以下のコードスニペットを貼り付け、‘return true’という行の上にあることを確認してください。 appdelegate swift 1 parseswift initialize(applicationid "paste your application id here", clientkey "paste your client id here", serverurl url(string "https //parseapi back4app com")!) あなたのappdelegate swiftファイルの最上部に、‘import uikit’のすぐ下に次のコードスニペットを含めてparseをモジュールとして含めることを確認してください。 appdelegate swift 1 import parseswift あなたのappdelegate swiftファイルは今、次のようになっているはずです appdelegate swift 1 import uikit 2 import parseswift 3 4 @main 5 class appdelegate uiresponder, uiapplicationdelegate { 6 7 8 9 func application( application uiapplication, didfinishlaunchingwithoptions launchoptions \[uiapplication launchoptionskey any]?) > bool { 10 // override point for customization after application launch 11 parseswift initialize(applicationid "paste your application id here", clientkey "paste your client id here", serverurl url(string "https //parseapi back4app com")!) 12 return true 13 } 14 15 // mark uiscenesession lifecycle 16 17 func application( application uiapplication, configurationforconnecting connectingscenesession uiscenesession, options uiscene connectionoptions) > uisceneconfiguration { 18 // called when a new scene session is being created 19 // use this method to select a configuration to create the new scene with 20 return uisceneconfiguration(name "default configuration", sessionrole connectingscenesession role) 21 } 22 23 func application( application uiapplication, diddiscardscenesessions scenesessions set\<uiscenesession>) { 24 // called when the user discards a scene session 25 // if any sessions were discarded while the application was not running, this will be called shortly after application\ didfinishlaunchingwithoptions 26 // use this method to release any resources that were specific to the discarded scenes, as they will not return 27 } 28 29 30 } 注意してください、 xcodeが no such module ‘parse’ と表示した場合、簡単な解決策があります。xcodeで「ターゲット > ビルド設定 > 検索パス > フレームワーク検索パス」を開き、次の2つの値を追加します:‘$(project dir)’ と ‘$(inherited)’。これでxcodeはparseモジュールを見つけることができるようになります。 back4appのウェブサイトでアプリダッシュボードに移動します。 アプリの設定に移動します: 機能 機能 をクリックし、 コア設定 コア設定 ブロック> サーバー サーバー を選択します。 あなたの appdelegate swift appdelegate swift ファイルに戻り、あなたの applicationid applicationid と clientkey clientkey を貼り付けます。 詳細は、私たちの 新しいparseアプリガイド をご覧ください。 3 接続をテストする viewcontroller swiftファイルを開きます。 ファイルの先頭で、‘import uikit’のすぐ下に次のコードスニペットを追加してparseをモジュールとして含めることを確認してください。 viewcontroller swift 1 import parseswift ‘viewdidload’という関数の中で、parseを設定するコードの下にコードスニペットを追加します。 viewcontroller swift 1 testparseconnection() 次に、viewdidload() メソッドの下に関数を追加します。 viewcontroller swift 1 struct gamescore parseobject { 2 // those are required for object 3 var objectid string? 4 var createdat date? 5 var updatedat date? 6 var acl parseacl? 7	 8 // your own properties 9 var score int = 0 10	 11 // custom initializer 12 init(score int) { 13 self score = score 14 } 15	 16 init(objectid string?) { 17 self objectid = objectid 18 } 19 } 20	 21 func testparseconnection(){ 22 let score = gamescore(score 10) 23 let score2 = gamescore(score 3) 24 score save { result in 25 switch result { 26 case success(let savedscore) 27 assert(savedscore objectid != nil) 28 assert(savedscore createdat != nil) 29 assert(savedscore updatedat != nil) 30 assert(savedscore acl == nil) 31 assert(savedscore score == 10) 32	 33 / to modify, need to make it a var as the value type 34 was initialized as immutable 35 / 36 var changedscore = savedscore 37 changedscore score = 200 38 changedscore save { result in 39 switch result { 40 case success(var savedchangedscore) 41 assert(savedchangedscore score == 200) 42 assert(savedscore objectid == savedchangedscore objectid) 43	 44 / note that savedchangedscore is mutable since it's 45 a var after success 46 / 47 savedchangedscore score = 500 48	 49 case failure(let error) 50 assertionfailure("error saving \\(error)") 51 } 52 } 53 case failure(let error) 54 assertionfailure("error saving \\(error)") 55 } 56 } 57 } 58 } デバイスまたはシミュレーターでアプリをビルドします ( コマンド コマンド + r r )。 メイン画面が表示されるまで待ちます。 にログインします back4appウェブサイト https //www back4app com/ アプリを見つけて、 ダッシュボード ダッシュボード をクリックします コア コア 。 に移動します ブラウザ ブラウザ 。 すべてが正常に動作していれば、 gamescore gamescore というクラスとその中の保存されたオブジェクトを見つけることができるはずです。 次のステップ この時点で、iosアプリの始め方を学びました。これから parse serverのコア機能 https //www back4app com/product/parse server と back4appのアドオン https //www back4app com/product/addons を探求する準備が整いました。 私たちの iosチュートリアル を歩き回ってもっと学ぶか、 ios sdkのためのparseオープンソースドキュメント を確認してください。