为什么以下代码会给我错误:
JSON写入中的类型无效(_SwiftValue).
此行引发错误:
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters)
Run Code Online (Sandbox Code Playgroud)
完整代码:
let parameters:Parameters = ["resource":[
[
"appUserCode":uuidString,
"productNFCode": self.nfCode!,
"status":code,
"applicationKey":appDelegate.api_key
]
]
]
do {
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters)
} catch {
// No-op
}
Run Code Online (Sandbox Code Playgroud) Worked on Xcode 10. Now in the beta I can't build I keep getting this error:
a "WatchKit" is not available when building for iOS Simulator. Consider using
#if !os(iOS)to conditionally import this framework.
我正在使用RestKit以及一些仅限Swift的框架,当我使用cocoapods use_frameworks时!标志,我得到编译错误.它在桥接头中找不到CoreData.h并且找不到RKValueTransformers.h
如果我删除标志,它都会正确编译.
有人见过这个吗?有解决方法吗?
这曾经在Swift 1.2中运行良好但现在给出错误:
"无法使用类型'的参数列表调用'geocodeAddressString'(String,completionHandler:([AnyObject]!,NSError!) - > Void)'"
geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in
if let placemark = placemarks?[0] as? CLPlacemark {
let annotation = MKPointAnnotation()
Run Code Online (Sandbox Code Playgroud)
编辑答案:
geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
Run Code Online (Sandbox Code Playgroud) 我突然不再在登录页面上看到电子邮件选项。它一直在那里,然后因为升级它现在消失了!
这是我声明提供者的方式:
let providers: [FUIAuthProvider] = [
FUIGoogleAuth(),
FUIFacebookAuth(),
FUITwitterAuth(),
FUIPhoneAuth(authUI:FUIAuth.defaultAuthUI()!)
]
Run Code Online (Sandbox Code Playgroud)
我没有看到任何新的 EmailAuth。显然它总是默认的,现在它不见了,我找不到任何变化的通知。
编辑:
尝试添加:
let providers: [FUIAuthProvider] = [
FUIEmailAuthProvider(), <====== compile error
FUIGoogleAuth(),
FUIFacebookAuth(),
FUITwitterAuth(),
FUIPhoneAuth(authUI:FUIAuth.defaultAuthUI()!)
]
Run Code Online (Sandbox Code Playgroud)
但得到这个错误:
无法构造“FUIEmailAuthProvider”,因为它没有可访问的初始值设定项
我正在撕扯我的头发,试图弄清楚如何在我的 SwiftUI 视图中绑定选择的值:
选择器需要绑定到从标签返回的 Int。我需要将此 Int 转换为 String 并设置绑定。如何?
struct ContentView: View {
@Binding var operatorValueString:String
var body: some View {
Picker(selection: queryType, label: Text("Query Type")) {
ForEach(0..<DM.si.operators.count) { index in
Text(DM.si.operators[index]).tag(index)
}
}.pickerStyle(SegmentedPickerStyle())
}
}
Run Code Online (Sandbox Code Playgroud)
如何以及在哪里设置我的 operatorValueString ?
operatorValueString = DM.si.operators[queryType] //不会编译。
我对如何在没有嵌套承诺的情况下重构我的代码进行读写有点困惑.在写入对象时,如果该对象设置了标志,我想用新计数更新其"相关"对象.我有两个问题.
1)来自读取然后写入的嵌套Promise.2)我应该回归什么
exports.updateRelationshipCounts = functions.firestore
.document('masterProduct/{nfCode}').onWrite((event) => {
//on writing of record:
var newProduct = event.data.data();
if (newProduct.isGlutenFreeYN === 'Y') {
console.log('Gluten Free');
//Update GF count in the Brand Object:
var db = admin.firestore();
var docRef = db.collection("masterBrand").doc(newProduct.brandNFCode);
var doc = docRef.get()
.then(doc => {
doc.glutenFreeCount = doc.glutenFreeCount + 1
docRef.set(newProduct.brand)
.then(function () {
console.log("Document successfully written!");
})
.catch(function (error) {
console.error("Error writing document: ", error);
});
})
.catch(err => {
console.log('Error getting document', err);
})
};
});
Run Code Online (Sandbox Code Playgroud)
另外它要我退货...没有?
这是我的数据库。
这是我的代码
let db = Firestore.firestore()
let defaults = UserDefaults.standard
let userId: String! = defaults.string(forKey: "UserUUID")
db.collection("Portfolios")
.whereField("users." + userId, isEqualTo: true)
.limit(to: 1)
.getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for portfolioDocument in querySnapshot!.documents {
print("Portfolio: \(portfolioDocument.documentID) => \(portfolioDocument.data())")
let portRef = db.collection("Portfolios").document("portfolioDocument.documentID")
portRef.getDocument { (document, error) in
if let document = document {
print("Document data: \(document.data())")
portRef.collection("Accounts").getDocuments() { (querySnapshot, err) in
if let err = err { …Run Code Online (Sandbox Code Playgroud) 我有以下导航链接:
NavigationLink(destination:
TrendSlider(
title: .constant(title),
col: .constant(self.dataModel.queryColumnSeasonWinPercentageTeam1),
opIndx: self.$dataModel.seasonWinPercentageTeam1OperatorIndxValue,
val: self.$dataModel.seasonWinPercentageTeam1SliderValue,
lBound: .constant(self.dataModel.seasonWinPercentageTeam1Values.first!) ,
uBound: .constant(self.dataModel.seasonWinPercentageTeam1Values.last!),
lRange: self.$dataModel.seasonWinPercentageTeam1RangeSliderLowerValue ,
uRange: self.$dataModel.seasonWinPercentageTeam1RangeSliderUpperValue,
step: .constant(1.0),
displayReadableQuery: $readableQuery
)) {
HStack {
if readableQuery.hasSuffix("IS ANY") {
Text(title)
Spacer()
Text("IS ANY").foregroundColor(Color("TPLightGrey"))
}else{
Text(readableQuery).foregroundColor(Color("TPOrange"))
}
}
}.simultaneousGesture(TapGesture().onEnded{
sendViewSelectionEvent(name: self.title, referral: "Game")
})
Run Code Online (Sandbox Code Playgroud)
如果我离开“.simultaneousGesture...”,则点击 Text 元素不会触发 NavigationLink 操作,但该行的其余部分确实有效。
如果我删除 .simultaneousGesture,则可以再次点击该行。
漏洞?