因此,我发现此代码可在用户仍在键入时查询您的数据库,但是该代码已过时并且我一直在对其进行更新,但是有一个错误,我不知道如何解决。
using JuMP
using NLopt
m = Model(solver=NLoptSolver(algorithm=:LD_MMA))
a1 = 2
b1 = 0
a2 = -1
b2 = 1
@variable(m, x1)
@variable(m, x2 >= 0)
@NLobjective(m, Min, sqrt(x2))
@NLconstraint(m, x2 >= (a1*x1+b1)^3)
@NLconstraint(m, x2 >= (a2*x1+b2)^3)
setvalue(x1, 1.234)
setvalue(x2, 5.678)
status = solve(m)
println("got ", getobjectivevalue(m), " at ", [getvalue(x1),getvalue(x2)])
我在最后一行出现错误,它说:
“任何”类型的值没有成员“值”
答案 0 :(得分:1)
snapshot.children
中的元素属于Any
类型,没有value
属性。要获得value
属性,您需要将u
强制转换为DataSnapshot
:
for userSnapshot in snapshot.children{
let userSnapshot = userSnapshot as! DataSnapshot
guard let dictionary = userSnapshot.value as? [String: Any] else { return }
user.name = dictionary["name"] as? String
}
或者,您将演员表放入循环中
for userSnapshot in in snapshot.children.allObjects as? [DataSnapshot] ?? [] {
guard let dictionary = userSnapshot.value as? [String: Any] else { return }
user.name = dictionary["name"] as? String
}