如何在firebase SwiftUI的地图数组中添加元素

How I can add element in array of map in firebase SwiftUI

提问人:Dmitry 提问时间:11/3/2023 最后编辑:jnpdxDmitry 更新时间:11/3/2023 访问量:57

问:

我在 Firebase 中有数据,我请求检查 requestdate == 我的日期我想向这个请求日期添加时间

  "booking_days": [
    {
      "date": "__Timestamp__2023-11-05T05:11:54.301Z",
      "day_off": false,
      "time": [
        "11:30"
      ]
    },
    {
      "date": "__Timestamp__2023-11-04T05:20:17.640Z",
      "day_off": false,
      "time": [
        "14:30"
      ]
    }
  ],

我尝试像这样的代码

   func setBookingTimeForExistingDay(userId: String, bookingDays: BookingDay, existingDay: Date) async throws {
        guard let bookingDay = try? encoder.encode(bookingDays) else {
            throw URLError(.badURL)
        }
        let orderBookingTime: [String : Any] = [DBPortfolioModel.CodingKeys.bookingDays.rawValue : FieldValue.arrayUnion([bookingDay])]

       
        try await portfolioUserDocument(userId: userId).setData(orderBookingTime, mergeFields: ["\(existingDay)"])
    }

我想要得到这样的结果

 "booking_days": [
    {
      "date": "__Timestamp__2023-11-05T05:11:54.301Z",
      "day_off": false,
      "time": [
        "11:30",
        "12:30"
      ]
    },
    {
      "date": "__Timestamp__2023-11-04T05:20:17.640Z",
      "day_off": false,
      "time": [
        "14:30"
      ]
    }
  ],
迅捷 火力基地

评论

0赞 workingdog support Ukraine 11/3/2023
你提到的代码在哪里?请注意,a 只是一个时间点 Dateif requestdate == my dateDate
0赞 Dmitry 11/3/2023
我在另一段代码中执行此操作,结果我得到的结果是我如何使用“date”: “MyDate()”booking_days数组对象调用并附加到字段“time”字符串值中的该对象

答: 暂无答案