使用功能并发送到单元格

时间:2019-05-04 16:31:51

标签: json swift

如何接收数据并发送到单元格上????

我正在跟踪一个已经存在并正在返回但要在单元格中保存的函数的模型

func getAllEstablishments(completion: @escaping (Result<[Establishment]>) -> Void) {
        var url = baseURL
        url.appendPathComponent("/api/establishment/list")

        let resultCompletion: (Result<[Establishment]>) -> Void = { result in
            do {
                let establishments = try result.unwrap()
               // completion(.success(value: nil))
                completion(.success(value: establishments))
                //completion(.success(value: nil))
                print("passou aqui get all")
            } catch {
                completion(.failure(error: error))
            }

        }

        request(url: url, isAuth: true, encoding: URLEncoding.default, completion: resultCompletion)
    }




 func fetchEstablishment(completion: ((Result<Void>) -> Void)? = nil) {
        app.networkManager.getAllEstablishments() { requestResult in

            do {
                let establishments = try requestResult.unwrap()

                try StorageHelper.store(establishments, to: StorageHelper.Directory.caches, as: "establishments.json")

                completion?(.success(value: ()))

            } catch let firstError {
                do {
                    _ = try StorageHelper.retrieve("establishments.json", from: StorageHelper.Directory.caches, as: [Establishment].self)
                    completion?(.success(value: ()))

                } catch {
                    completion?(.failure(error: firstError))

                }
            }
        }
    }


我正在跟踪一个已经存在并正在返回但要在单元格中保存的函数的模型

0 个答案:

没有答案