내일배움캠프 iOS

iOS) TIL # 67 실전프로젝트 - 3

yjuni22 2025. 1. 23. 20:45

 

4. Post 모델 구현

struct Post: Codable {
    let createdDate: Timestamp?
    let nickName: String
    let positionSearch: String    // "구인" 또는 "구직"
    let position: String          // 직무
    let availableTime: String     // 가능 시간
    let techstack: [String]       // 기술 스택 배열
    let urgencyLevel: String      // 시급성
    let specificity: String       // 아이디어상황
    let recruits: String          // 모집 인원
    let meeting: String           // 협업방식
    let experience: String        // 경험
    let title: String            // 제목
    let detail: String           // 상세 내용
}
 

 

5. 게시글 작성 및 Firestore 저장

let data = [
    "createdDate": FieldValue.serverTimestamp(),
    "nickName": nickName,
    "positionSearch": positionSearch,
    // ... 기타 필드
]

db.collection("posts").addDocument(data: data)
 
 

6. 게시글 표시 테스트 뷰 구현

 Firestore 데이터 가져오

 

 
db.collection("posts").limit(to: 1).getDocuments { [weak self] snapshot, error in
    guard let document = snapshot?.documents.first else { return }
    let data = document.data()
    // Post 객체로 변환
}
 

 

https://hello-developer.tistory.com/53

 

[Swift] Cloud Firestore(2) 실습해보기

지난 포스팅에서는 간단하게 Cloud Firestore에 데이터가 어떻게 저장되는지 전체적인 구조를 살펴보았는데요~!! 데이터 구조를 잘 모르면 먼저 구조부터 확실하게 알고 실습을 시작하는게 좋습니

hello-developer.tistory.com