Firebase或Swift没有检测到变音符号 [英] Firebase or Swift not detecting umlauts
问题描述
Firebase
数据库/存储中发现了一些最奇怪的东西。问题是,我不知道Firebase或Swift是否没有检测到变音符号,例如(ä,ö,ü)。 图片添加到Firebase存储,然后将它们下载到 tableview
中。我的一些 .png
文件在标题中有元音变音(Röda.png
)。
现在如果我下载它们,问题就会出现。我的下载 url
的唯一时间是 nil
是文件名包含我在说的元音变音。
所以我尝试了一些替代方法,如 这是 Horray for Unicode! 简单的回答是,不,我们实际上没有做任何特别的事情,基本上我们所做的是: 我的想法是: 返回 Apple必须先对字符串进行规范化在Swift中比较(可能是一个合理的做法,否则会导致像这这样的错误,其中字符串是相同的,但比较不同)。事实证明,这正是他们所做的事情(请参阅他们的<扩展字形集群>部分 String 因此,在命名包含Unicode字符的文件时,请确保选择标准表示(C,D,KC或KD),并在创建引用时始终使用它。 I found some weirdest thing in I did some easy things with Firebase like upload images to Firebase Storage and then download them into So the problem occurs now if I download them. The only time my download So I tried some alternatives like in This is the code when
Horray for Unicode! The short answer is that no, we're actually not doing anything special here. Basically all we do under the hood is: What blows my mind is that: returns Apple must be normalizing strings before comparison in Swift (probably a reasonable thing to do, since otherwise it leads to bugs like this where strings are "the same" but compare differently). Turns out, this is exactly what they do (see the "Extended Grapheme Clusters" section of their docs). So, when you provide two different characters in Swift, they're being propagated to Obj-C as different characters and thus are encoded differently. Not a bug, just one of the many differences between Swift's Thus, when naming files that contain Unicode characters, make sure to pick a standard representation (C,D,KC, or KD) and always use it when creating references.
这篇关于Firebase或Swift没有检测到变音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! HTML
ö - & ouml;
。但是这不起作用。你们可以给我一些建议吗?我不能使用ö - o
,ü - ü
等。
nil
时尝试将某些值设置为 Firebase :
FIRStorage.storage()。reference()
.child(\(productImageref !)。png)
.downloadURLWithCompletion({(url,error)in
$ b FIRDatabase.database()。reference()
.child(Snuses ).child(productImageref!)。child(productUrl)
.setValue(url!.absoluteString)
$ b $ let resource = Resource(downloadURL:url !, cacheKey:productImageref)
pre > //这是https://cloud.google.com/storage/docs/json_api/中没有&因为查询参数
类型和Obj-C的
N的列表SString * const kGCSObjectAllowedCharacterSet =
@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -._〜!$'()* +,; =:@;
- (可为空的NSString *)GCSEscapedString:(NSString *)string {
NSCharacterSet * allowedCharacters =
[NSCharacterSet characterSetWithCharactersInString:kGCSObjectAllowedCharacterSet];
return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
$ / code>
let str1 =o\u {308}//分解:拉丁小写字母o +结合diaeresis
pre>
let str2 =\u { f6}/ / precomposed:拉丁字母o与diaeresis
print(str1,str2,str1 == str2)//öötrue
true
。在Objective-C中(Firebase存储客户端是内置的),它完全不应该,因为它们是两个完全不同的字符(实际上, str1
是 2
,而 str2
的长度在Obj中是 1
-C,而在Swift中,我假设两者的答案都是 1
。)
NSString
类型之间的许多区别之一。如果有疑问,请选择您希望遵循的规范化表示法,但是作为图书馆开发人员,我们很难为您选择该表示法。
let imageName =smorgasbörd.jpg
let path =images / \(imageName)
let decomposedPath = path.decomposedStringWithCanonicalMapping // Unicode Form D
let ref = FIRStorage.storage()。reference()。child(decomposedPath)
//使用这个引用,你将总是得到相同的对象
Firebase
Database/Storage. The thing is that I don't know if Firebase or Swift is not detecting umlauts e.g(ä, ö, ü).tableview
. Some of my .png
files had umlauts in the title for example(Röda.png
).url
is nil
is if the file name contains the umlauts I was talking about.HTML
ö - ö
. But this is not working. Can you guys suggest me something? I can't use ö - o
, ü - u
etc.url
is nil
when trying to set some values into Firebase:FIRStorage.storage().reference()
.child("\(productImageref!).png")
.downloadURLWithCompletion({(url, error)in
FIRDatabase.database().reference()
.child("Snuses").child(productImageref!).child("productUrl")
.setValue(url!.absoluteString)
let resource = Resource(downloadURL: url!, cacheKey: productImageref)
// This is the list at https://cloud.google.com/storage/docs/json_api/ without the & because query parameters
NSString *const kGCSObjectAllowedCharacterSet =
@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$'()*+,;=:@";
- (nullable NSString *)GCSEscapedString:(NSString *)string {
NSCharacterSet *allowedCharacters =
[NSCharacterSet characterSetWithCharactersInString:kGCSObjectAllowedCharacterSet];
return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
}
let str1 = "o\u{308}" // decomposed : latin small letter o + combining diaeresis
let str2 = "\u{f6}" // precomposed: latin small letter o with diaeresis
print(str1, str2, str1 == str2) // ö ö true
true
. In Objective-C (which the Firebase Storage client is built in), it totally shouldn't, as they're two totally different characters (in actuality, the length of str1
is 2
while the length of str2
is 1
in Obj-C, while in Swift I assume the answer is 1
for both).String
type and Obj-C's NSString
type. When in doubt, choose a canonical representation you expect and stick with it, but as a library developer, it's very hard for us to choose that representation for you.let imageName = "smorgasbörd.jpg"
let path = "images/\(imageName)"
let decomposedPath = path.decomposedStringWithCanonicalMapping // Unicode Form D
let ref = FIRStorage.storage().reference().child(decomposedPath)
// use this ref and you'll always get the same objects