iOS
Parse Swift SDK
iOS 스위프트 프로젝트에 Parse Swift 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 패키지 추가 스위프트 패키지 관리자 아직 parse ios sdk를 설치하지 않았다면 이 단계를 따르세요 더 새로운 버전의 xcode 에는 swift 패키지 관리자가 내장되어 있습니다 이것은 parse swift sdk를 프로젝트에 설치하고 업데이트하는 가장 쉽고 좋은 방법입니다 현재 우리는 parse swift sdk를 설치하는 데 이 방법을 사용하는 것을 권장합니다 ( 파일 파일 ) 메뉴에서 ( 스위프트 패키지 스위프트 패키지 )를 선택한 다음 ( 패키지 의존성 추가 패키지 의존성 추가 ) on the ( 패키지 리포지토리 선택 패키지 리포지토리 선택 ) window, paste the url for the parse swift sdk github website ( https //github com/parse community/parse swift ) and click 다음 다음 ( 저장소 저장소 ) 창에서, 버전 버전 , 브랜치 브랜치 또는 특정 커밋 커밋 선호하는 방법을 선택하고 다음 다음 기다리세요 xcode xcode 가 모든 parse swift parse swift 의존성을 해결한 후 다음 다음 ht 패키지 제품이 확인되었는지 확인하십시오 parseswift parseswift 가 체크되어 있고 귀하의 대상이 대상 추가 대상 추가 로 올바르게 선택되었으면, 다음 다음 swift 패키지는 프로젝트 바로 아래의 종속성 트리에 나타나야 하며, 오른쪽에 버전이 표시됩니다 업데이트가 필요하면 parseswift parseswift 패키지를 선택하고, dependencies 트리에서 오른쪽 클릭한 후 패키지 업데이트 패키지 업데이트 이 과정은 모든 것을 자동으로 업데이트합니다 축하합니다! 이제 parse swift ios sdk를 설치했습니다 cocoapods 1 1 parse swift ios sdk 설치 아직 parse swift ios sdk를 설치하지 않았다면 이 단계를 따르세요 xcode는 cocoapods 를 swift 및 objective c cocoa 프로젝트의 의존성 관리자로 사용할 수 있습니다 참고할 수 있습니다 cocoapods 시작하기 가이드 추가 세부정보는 cocoapods를 설치하려면 터미널을 열고, 다음 코드 스니펫을 복사하여 터미널에 붙여넣고 enter 키를 누르세요 cocoapods는 비밀번호를 입력한 후 자동으로 설치되어야 합니다 문제가 발생하면 로컬 ruby 버전을 업그레이드해야 할 수 있습니다 다음으로 xcode 프로젝트 폴더를 열고 해당 폴더에서 터미널 창을 엽니다 이제 podfile을 생성할 것입니다 다음 코드 스니펫을 복사하여 터미널에 붙여넣고 enter 키를 누르세요 이제 폴더에 podfile이 표시되면 올바르게 수행한 것입니다 조심하세요, podfile이 보이지 않으면 터미널이 실제로 프로젝트 폴더 안에 있는지 확인하세요 다음으로 xcode 또는 다른 텍스트 편집기로 podfile을 열고 각 타겟 아래에 “pod ‘parse’”를 추가하세요 당신의 podfile은 다음과 비슷할 것입니다 이제 parse swift를 프로젝트에 추가할 것입니다 터미널이 프로젝트 폴더에 열려 있는지 확인하세요 다음 코드 스니펫을 복사하여 터미널에 붙여넣고 enter 키를 누르세요 코코아팟이 프로젝트를 작업 공간으로 다시 빌드할 것이며, 이제 귀하의 프로젝트는 다음과 같이 보일 것입니다 이미 xcode 프로젝트를 열었다면 닫으세요 이제부터는 프로젝트 파일 대신 워크스페이스 파일을 열게 됩니다 워크스페이스 파일을 더블 클릭하여 엽니다 축하합니다! 이제 parse ios sdk를 설치했습니다 2 파스 앱 연결하기 프로젝트의 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에서 ‘target > build settings > search paths > framework search paths’를 열고 두 값을 추가하세요 ‘$(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 오픈 소스 문서 를 확인하세요