I want to get map data from cloud Firestore
,this is java code I need to access the same database in swift. I attached the java code and database structure picture for reference.
FirebaseFirestore db = FirebaseFirestore.getInstance();
DocumentReference mDocRef = db.collection("hmdhAcademy").document("notifications");
mDocRef.get().addOnCompleteListener(task -> {
if ( task.isSuccessful() ) {
DocumentSnapshot documentSnapshot = task.getResult();
if ( documentSnapshot != null && documentSnapshot.exists() ){
notificationList = (ArrayList) documentSnapshot.get("userNotifications");
adapter = new NotificationAdapter(this,notificationList);
mRecyclerView.setAdapter(adapter);
alertDialog.dismiss();
}
}
else {
Toast.makeText(NotificationActivity.this,"Check Internet Connection",Toast.LENGTH_SHORT).show();
alertDialog.dismiss();
}
});
if ( list.get(i) instanceof HashMap ){
final Intent intent = new Intent(mContext,NotificationDetail.class);
String title = (String)((HashMap)list.get((list.size()-1)-i)).get("title");
String body = (String)((HashMap)list.get((list.size()-1)-i)).get("body");
String image = (String)((HashMap)list.get((list.size()-1)-i)).get("notiImage");
String detail = (String)((HashMap)list.get((list.size()-1)-i)).get("detail");
}
I need the same title, body, notiImage and detail.
Please help me with that, I'm looking for an answer anywhere but failed.
Try this code:
Or try this way:
Create a struct
Create a variable in your ViewController:
Map all your data in one line in your firestore code