- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
---------RTV通知------------------
import Foundation
///Notification Info
public class RTVNotification: Codable {
public let id: String
public let title: String
public let comment: String
public let urlString: String
public let supportedDevice: String
public let publishStartDateString: String
required public init(from decoder: Decoder) throws {
id = try decoder.decode(CodingKeys.id)
title = try decoder.decode(CodingKeys.title)
comment = try decoder.decode(CodingKeys.comment)
urlString = try decoder.decode(CodingKeys.urlString)
supportedDevice = try decoder.decode(CodingKeys.supportedDevice)
publishStartDateString = try decoder.decode(CodingKeys.publishStartDateString)
}
public func encode(to encoder: Encoder) throws {}
}
// MARK: - CodingKeys
private extension RTVNotification {
enum CodingKeys: String, CodingKey {
case id = "id"
case title = "name"
case comment = "comment"
case urlString = "url"
case supportedDevice = "supported_device"
case publishStartDateString = "show_started_at"
}
}
---------- RTV信息列表----------------------------------------
import Foundation
// MARK: InformationList
public class RTVInformationList: Codable {
public let offset: Int
public let count: Int
public let maxCount: Int
public let notifications: [RTVNotification]
required public init(from decoder: Decoder) throws {
offset = try decoder.decodeInt(CodingKeys.offset)
count = try decoder.decodeInt(CodingKeys.count)
maxCount = try decoder.decodeInt(CodingKeys.maxCount)
notifications = (try? decoder.decode(CodingKeys.notifications)) ?? []
}
public func encode(to encoder: Encoder) throws {}
}
// MARK: - CodingKeys
private extension RTVInformationList {
enum CodingKeys: String, CodingKey {
case offset = "offset"
case count = "count"
case maxCount = "max_count"
case notifications = "information_list"
}
}
---------------通知项目----------------------
public class NotificationItem: Codable {
public let id: String
public let title: String
public let comment: String
public let urlString: String
public let supportedDevice: String
public var publishStartDateString: String
init(id: String,
title: String,
comment: String,
urlString: String,
supportedDevice: String,
publishStartDateString: String) {
self.id = id
self.title = title
self.comment = comment
self.urlString = urlString
self.supportedDevice = supportedDevice
self.publishStartDateString = publishStartDateString
}
}
extension NotificationItem {
static func instantiate(with notification: RTVNotification) -> NotificationItem {
NotificationItem(
id: notification.id,
title: notification.title,
comment: notification.comment,
urlString: notification.urlString,
supportedDevice: notification.supportedDevice,
publishStartDateString: notification.publishStartDateString)
}
}
---------------- 设置 View 模型--------------------
public class SettingsViewModel: ViewModel {
var item = [NotificationItem]()
public var fetchedNotifications: Driver<[RTVNotification]> = .empty()
public var apiErrorEvents: Driver<RTVAPIError> = .empty()
public var notificationCount: Driver<Int> = .empty()
public func bindNotificationEvents(with trigger: Driver<Void>) {
let webService: Driver<RTVInformationListWebService> = trigger
.map { RTVInformationListParameters() }
.webService()
let result = webService.request()
apiErrorEvents = Driver.merge(apiErrorEvents, result.error())
notificationCount = result.success().map {$0.informationList.maxCount }
fetchedNotifications = result.success()
.map {$0.informationList.notifications}
----> .map {$0.map {NotificationItem.instantiate(with: $0)}}
}
}
收到错误:- 无法将类型“NotificationItem”的值转换为闭包结果类型“RTVNotification”我不明白如何转换类型。我是编程新手
最佳答案
----> .map {$0.map {NotificationItem.instantiate(with: $0)}}
fetchedNotifications 变量已声明为类型:Driver<[RTVNotification]>。 $0.map {NotificationItem.instantiate(with: $0)} 现在表示它应该是 Driver<[NotificationItem]> 类型。这行不通。
如果结果应为 Driver<[NotificationItem]>,则创建一个具有正确类型的新变量。
下面是更简短的示例:
let numbers: [Int] = [5,6,5]
var newNumbers: [Int] = []
/// This will provide you with an error of:
/// Cannot convert value of type 'String' to closure result type 'Int'
newNumbers = numbers.map {
return "\($0)"
}
// correctNewNumbers is now converted correctly to a [String]
let correctNewNumbers = numbers.map {
return "\($0)"
}
关于swift - 出现错误 :-Cannot convert value of type 'NotificationItem' to closure result type 'RTVNotification' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58680640/
我有点困惑为什么在 RoutineRetrieved 函数中分配 ACTIVITYIMAGE 时使用 result.getInt(2) 并在分配 SLOT 时使用 result.getInt(3)..
我是android领域的新手,我想从响应json数组访问每个结果元素,但我无法做到这一点,我试图获取每个元素,但我只得到一个值“rohit1”是第一个元素。请帮助我。 我是 rohit parmar,
我只有从 sql 查询返回的一行 (count(*)),但在执行包时,它向我显示上述错误,并且包失败。 我将结果类型设置为“单行”,并将查询的输出(select count(*) as 'result
我正在尝试使用Diesel将简单的原始SQL转换为MySQL,如本示例所示: https://docs.diesel.rs/diesel/fn.sql_query.html let users = s
我正在尝试 Play 框架的第一个示例,但出现了此错误 在我的路线文件中: # API # ~~~~ GET /api/geotweets/index controllers.api.GeoTw
这段代码可以返回null吗? (this.Result == Result.OK) 此行(或类似行)是否可以返回除 true 或 false 之外的任何内容(例如 null)? 最佳答案 (this.
我有一个 SSIS 执行 SQL 任务。它返回一个完整的结果集(即一个表)。但是,当我执行包时出现以下错误。我已经正确地为返回的结果集命名。 [执行 SQL 任务] 错误:对于完整的结果集和 XML
最近我刚刚将 swift 2.3 项目转换为 3.2,alamofire 也得到了转换,我收到了很多问题,其中大部分都已解决,现在我被给定的两个问题所困扰 问题在 alamofire 的 Respon
我在 R 中收到以下错误消息: Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set", : Unable to r
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 去年关闭。
我正在使用一个简单的命令运行以下存储过程sp_MSforeachdb。我的问题是如何限制结果仅显示至少有 1 条记录满足命令的数据库: 这是我的存储过程: EXECUTE master.sys.sp_
我在单独的线程中运行一些代码: fn f1() -> Result { Err("err1".to_string()) } fn f2() -> Result { Err("err2"
我在这里尝试使用 AsyncTask 从 OWM API 显示 7 天的天气预报。 doInBackground(String...param) 方法也工作正常。我检查了 LOGCAT。 异步完成执行
我已经创建了mysql的索引和全文索引,后端存储引擎是MyISAM。 mysql> show index from play_movie; +------------+------------+---
我有一个表articles,它的结构如下: id, name, date, contents 我有一个表authors,它的结构如下: id, article_id, name, email 一篇文章
我很困惑我们是否应该创建单独的 API 来获取结果和结果计数,或者我们应该只根据结果 API 中的查询字符串来获取计数。 /api/results/ : Fetches all records /ap
我正在制作一个将两个数字相除的系统,如果第二个数字不存在,它将选择第一个数字。这是代码: let new_num: f32 = match num1/num2 { Ok(num) => n
这个问题在这里已经有了答案: Why am I getting "unused Result which must be used ... Result may be an Err variant,
我正在修改 the texture synth 中的示例之一项目: use texture_synthesis as ts; fn main() -> Result { //create a
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: ^ operator in java 我假设 c ^ d是一个类似“的幂”的计算,所以c = 5 , d = 2 ,
我是一名优秀的程序员,十分优秀!