- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想要做的是:让用户对商店进行评分,然后更新 Firebase 中的 storeRate
值。
点击 POST 后,出现错误:
'NSInvalidArgumentException', reason: 'Invalid number value (infinite) in JSON write'
//Initialize Variables
var storeRateIni = 0.0
var reviewCount = 0.0
var receivedId = 1 //receive storeId from parent View Controller
refStore = Database.database().reference().child("stores")
refUpdate = Database.database().reference().child("stores").child(String(receivedId))
refStore.observe(DataEventType.value, with: {(snapshot) in
if snapshot.childrenCount > 0{
for store in snapshot.children.allObjects as! [DataSnapshot]{
let storeObject = store.value as? [String: AnyObject]
let storeId = storeObject?["storeId"] as! Int
if (storeId == self.receivedId) {
//Get value store in Firebase
let storeRate = storeObject?["storeRate"] as! Double
let storeReviewCount = storeObject?["storeReviewsCount"] as! Double
//Do the calculation
let storeRateUpdate = (storeRate + self.userRate.rating) / storeReviewCount
//Update to Firebase
self.reviewCount = storeReviewCount + 1
self.storeRateIni = storeRateUpdate
self.refUpdate.updateChildValues(["storeRate": self.storeRateIni])
self.refUpdate.updateChildValues(["storeReviewsCount": self.reviewCount])
}}}})
最佳答案
这一行,
let storeRateUpdate = (storeRate + self.userRate.rating) / storeReviewCount
当 storeReviewCount == 0.0
时生成 Double.inifinity
,这在 JSON 中无法表示。
您可能需要将 storeReviewCount == 0.0
的情况与其他情况分开处理。
例如:
let storeRateUpdate = storeReviewCount == 0.0
? 0.0
: (storeRate + self.userRate.rating) / storeReviewCount
关于json - 'NSInvalidArgumentException',原因 : 'Invalid number value (infinite) in JSON write' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55931424/
我正在使用 NDK 为 Android 编写一个实用程序。 在我的实用程序中,我 fork 了一个进程,并在该进程中运行以下代码: //Screenshot thread int i = 0; for
我是 React 新手,正在构建一个表单。该表单由多个组件组成的集合组成。组件之一是文本字段。 我想创建一个按钮,只需单击即可添加无限数量的相同文本字段组件。我对如何执行此操作感到困惑,并且在网上找不
我需要每 5 秒无限地写入一个文件 (.txt)这是我的代码: #include #include #include #include #include using namespace st
出于好奇,是 全部 无限循环不好? 如果您运行无限循环,会发生什么不良影响和后果? 另外,如果它们不全是坏的,您能否举一些例子,它们何时可以用于有意义的目的? 他们是否需要关闭实例?例如,我们总是在
下面是我的智能合约。当我将它放入混音中时,我会收到有关以下每个功能的警告。 函数 MedicalRecord.addNote(bytes32,bytes32) 的 Gas 要求高:无限。 函数 Med
CPDT的第三章简要讨论了为什么Coq中禁止使用负感应类型。如果我们有 Inductive term : Set := | App : term -> term -> term | Abs : (te
我有一个包含 6 个页面且启用分页的 UICollectionView 和一个 UIPageControl。我想要的是,当我来到最后一页时,如果我向右拖动,UICollectionView 会从第一页
如何以编程方式在 Excel 工作表中创建“无限”符号? 最好来自 Java...但也欢迎其他提示。 谢谢。 最佳答案 “无穷大符号”字符位于 unicode 的代码点 0x221E 中。执行此操作的
如果我想迭代值 0 到 255 并且我使用无符号字节作为计数器,当计数器达到 255 时返回到 0 并进行无限循环。 for (ubyte i = 0; i < ubyte.max; i++)
如果需要全部32位来存储从-2^31到2^31,它如何存储+和-无穷大?它使用更多内存吗?存储这些值是否良好且安全? 更新:感谢答案,我知道只有 float 据类型可以存储 Inf 值,整数不能。 最
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
在下面的设置中,如何绘制一条通过两点的“无限”线? var context = document.getElementById("canvas").getContext("2d"); var poin
我正在测试一个简单的汇编函数 (SPARC)。该函数如下,应该有两个参数,x 和 *str,并计算 x 在 *str 中出现的次数。但是,该函数会导致无限循环。我正在使用 C 来调用汇编函数,这也在下
我有很多内容要在网站上显示,因此我需要使用“无限”滚动解决方案,当用户滚动到当前加载内容的末尾时加载内容。但是,我确切地知道有多少数据,我希望用户对此有所了解。我不喜欢滚动条如何让你看起来快到内容的末
我想实现无限滚动。下面是我的布局的简短形式。因为我有一些相对定位的元素,javascript 滚动事件不会触发。 如何解决此问题才能触发滚动事件并实现无限滚动? 我的主要布局是:
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题吗? 更新问题,以便 editing this post 提供事实和引用来回答它. 关闭3年前。 Improve th
如何定义类型 InfiniteFunction ,这是一个函数,调用时返回另一个 InfiniteFunction 类型看起来像: () => () => () => ... // infinite
我正在尝试为此模式创建匹配项: /page/some/thing/is/written/here 其中/page 将始终匹配 a-zA-Z0-9 并且/page 之后的所有内容都可以包含字符 a-zA
我正在使用一个“通用”js 片段,它应该检测用户是否滚动到文档底部: $(window).scroll(function() { if ($(window).scrollTop()
当我尝试初始化 Fabric ui 日期选择器字段的值时,我收到 @@redux-form/INITIALIZE 消息的无限循环 function mapStateToProps(state) {
我是一名优秀的程序员,十分优秀!