質問編集履歴

1

現在のコードとやりたいことを追記

2018/06/07 10:17

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -49,3 +49,113 @@
49
49
 
50
50
 
51
51
  別々に保存することなく、ユーザー情報を保存することは可能でしょうか?
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+ ### 追記
60
+
61
+ - 現在のコード
62
+
63
+
64
+
65
+ ```
66
+
67
+ func postStrings() {
68
+
69
+ let currentUser = Auth.auth().currentUser
70
+
71
+
72
+
73
+
74
+
75
+ //保存するデータをセット
76
+
77
+ let post: [String: Any] = [
78
+
79
+ "category": category!,
80
+
81
+ "postUid": currentUser.uid,
82
+
83
+ "postUserName": currentUser.displayName!,
84
+
85
+ "postUserPhotoURL": currentUser.photoURL!,
86
+
87
+ "placeName": placeName!,
88
+
89
+ "singleWord": singleWord!,
90
+
91
+ "createDate": self.date
92
+
93
+ ]
94
+
95
+ SVProgressHUD.show()
96
+
97
+ self.defaultStore.collection("Post").addDocument(data: post) { (error) in
98
+
99
+ if let error = error {
100
+
101
+ SVProgressHUD.showError(withStatus: error.localizedDescription)
102
+
103
+ SVProgressHUD.dismiss()
104
+
105
+ } else {
106
+
107
+ SVProgressHUD.dismiss()
108
+
109
+ SVProgressHUD.showSuccess(withStatus: "投稿完了")
110
+
111
+ //閉じる
112
+
113
+ self.dismiss(animated: true, completion: nil)
114
+
115
+ }
116
+
117
+ }
118
+
119
+ }
120
+
121
+ ```
122
+
123
+
124
+
125
+ 今、ユーザー名、ユーザーIdを別々のコレクションに保存しています。("postUid","postUserName","postUserPhotoURL")
126
+
127
+
128
+
129
+ - やりたいこと
130
+
131
+ ユーザ情報をいちいち別々に保存することなく、まとめて「ユーザー情報」として保存したいです。
132
+
133
+ (ユーザー情報を同じコレクションに保存するイメージ)
134
+
135
+ ```
136
+
137
+ userInfo
138
+
139
+ |--uid
140
+
141
+ |--displayName
142
+
143
+ |--photoURL
144
+
145
+ ````
146
+
147
+
148
+
149
+
150
+
151
+ また、以下のようにすると上記のエラーが出ます。(Unsupported type: FIRUser )
152
+
153
+ ```
154
+
155
+ let post: [String: Any] = [
156
+
157
+ "userInfo": currentUser,
158
+
159
+ ]
160
+
161
+ ```