我在上传图片时实施了Firebase友好聊天示例。使用可选字符串获取响应。错过了什么?
Optional(FIRStorageMetadata 0x7fc84aced790: {
bucket = "abc.appspot.com";
contentEncoding = identity;
contentType = "image/jpeg";
downloadTokens = "abctoken";
generation = 1231231;
metageneration = 1;
name = "Optional(\"S5CKnKUykANdxSvZ3wujpMXHTvg1\")/494509700277/asset.JPG";
timeCreated = "2016-09-02T11:49:00.114Z";
updated = "2016-09-02T11:49:00.114Z";
})
我的代码:
let filePath = "(FIRAuth.auth()!.currentUser!.uid)/(Int(NSDate.timeIntervalSinceReferenceDate() * 1000))/(referenceUrl.lastPathComponent!)"
在样本中使用可选值(?)编写,因此我将其转换为(!)
答案 0 :(得分:1)
在swift中你必须强制展开值以避免这种情况(但要确保,它不是零)。
"\(optionalValue!)"
或以标准方式打开它
if let value = optionalValue {
someFIRMethod("\(value)")
}