我试图找出iOS中十进制键盘键盘使用的小数点分隔符,因此我可以将用户输入的字符串转换为带有NumberFormatter
和返回的数字.
由于我想用现有值预先填充文本字段,我需要一个数字格式化程序,它使用与十进制键盘相同的小数点分隔符.
我的设备设置的语言(德语,德国)使用逗号作为小数分隔符.我已将iOS配置为将德语键盘作为主键盘和活动键盘以及英语(US,QWERTY)作为辅助键盘.
我正在处理的应用程序只有一个基础本地化,这是英语.在方案设置中,区域和语言设置为系统默认值.
如果我运行我的应用程序,小数键盘键盘使用的小数分隔符是".",这是en-US键盘使用的小数分隔符,但不是de-DE键盘.普通的字母键盘显示德语键盘布局.
如果我在iOS设备上删除了en-US键盘,则小数点分隔符将更改为",".
如何可靠地找出小数位键盘使用哪个小数点分隔符?
到目前为止,我尝试过的解决方案都没有工作:
decimalSeparator
的NumberFormatter
总是给人"".Locale.current.decimalSeparator
始终返回",".textField.textInputMode?.primaryLanguage
弄清楚语言环境总是返回de-DE
.Bundle.main.preferredLocalizations
找出由应用程序总是返回使用的本地化en
.这是数字格式化程序的配置方式:
let numberFormatter = NumberFormatter()
numberFormatter.minimumIntegerDigits = 1
numberFormatter.minimumFractionDigits = 0
numberFormatter.maximumFractionDigits = 2
Run Code Online (Sandbox Code Playgroud)
编辑:似乎可以通过查找活动文本输入模式和应用程序本地化之间的匹配来确定小数位垫使用的区域设置:
let inputLocales = UITextInputMode.activeInputModes.compactMap {$0.primaryLanguage}.map(Locale.init(identifier:))
let localizations = Bundle.main.preferredLocalizations.map(Locale.init(identifier:))
let locale = inputLocales.flatMap { l in localizations.map {(l, $0)}}
.filter { preferredLanguage, preferredLocalization in
if preferredLocalization.regionCode == nil || preferredLanguage.regionCode == nil {
return preferredLanguage.languageCode == …
Run Code Online (Sandbox Code Playgroud) 我试图在 Xcode 中以发布模式运行 Swift 包的测试目标,而不生成 Xcode 项目。
但是,当我将测试方案的构建配置设置为发布时,构建会失败,因为缺少使用-enable-testing
时必须传递给编译器的标志。@testable import
如何在 Xcode 中为 Swift 包添加此标志?请注意,传统的构建配置选项不可用,因为不存在 Xcode 项目。添加-Xswiftc -enable-testing
为测试方案的启动参数不起作用。
我从来没有用过NSBeep
。我已经导入AppKit.framework
到项目中。在 Xcode 8.2 和 Swift 3 下,我有
import AppKit
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillFinishLaunching(_ notification: Notification) {
NSBeep()
}
}
Run Code Online (Sandbox Code Playgroud)
而且没有哔哔声。我究竟做错了什么?谢谢。
所以我现在正在研究一个解析底部链接的JSON Api的程序
当我运行代码时,我得到一些输出,但不是全部
主要是为可选类型的动漫,这是好的,因为它表明它的工作,但我也想访问名称和发布日期和语言,但我不知道如何在swift 4中使用这样的JSON数组.我会附上我的目前的代码如下.
import UIKit
struct AnimeJsonStuff: Decodable {
let data: [AnimeDataArray]
}
struct AnimeDataArray: Decodable {
let type: String?
}
class OsuHomeController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
func jsonDecoding() {
let jsonUrlString = "https://kitsu.io/api/edge/anime"
guard let url = URL(string: jsonUrlString) else {return} //
URLSession.shared.dataTask(with: url) { (data, response, err) in
guard let data = data else {return}
do {
let animeJsonStuff = try JSONDecoder().decode(AnimeJsonStuff.self, from: data)
print(animeJsonStuff.data)
let animeDataArray = try JSONDecoder().decode(AnimeDataArray.self, from: data)
print(animeDataArray.type as Any)
} catch …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 SpaCy 中训练文本分类管道:
import spacy
nlp = spacy.load("en_core_web_sm")
nlp.add_pipe("textcat", last=True)
other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'textcat']
with nlp.disable_pipes(*other_pipes):
optimizer = nlp.begin_training()
# training logic
Run Code Online (Sandbox Code Playgroud)
但是,每次我打电话时nlp.begin_training()
,我都会收到错误
ValueError: [E955] Can't find table(s) lexeme_norm for language 'en' in spacy-lookups-data. Make sure you have the package installed or provide your own lookup tables if no default lookups are available for your language.
Run Code Online (Sandbox Code Playgroud)
运行python3 -m spacy validate
返回
? Loaded compatibility table
================= Installed pipeline packages (spaCy …
Run Code Online (Sandbox Code Playgroud) 使用 LLDB,我可以为类型添加自定义摘要:
(lldb) type summary add -s "This is a Foo" Baz.Foo
Run Code Online (Sandbox Code Playgroud)
但是,对于具有两个或多个泛型的泛型,我无法执行此操作。
给定一个Foo
具有两个或多个泛型类型的模块 Baz :
(lldb) type summary add -s "This is a Foo" Baz.Foo
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法;都没有成功:
type summary add -s "This is a Foo" Baz.Foo
type summary add -s "This is a Foo" Baz.Foo<A, B>
type summary add -s "This is a Foo" Baz.Foo<Float, Float>
type summary add -s "This is a Foo" Baz.Foo<Bar, Bar2>
type summary add -s "This is a Foo" Baz.Foo<Float>
在所有情况下,打印的是标准描述而不是自定义描述。
那么如何为具有两个或多个泛型的泛型添加自定义摘要,理想情况下无需为Bar …
我试图依次调用3个函数,但是每个函数都必须先完成才能运行下一个函数。每个函数都有一个完成处理程序,该处理程序在完成时调用另一个函数。在在线阅读了很多有关调度队列的信息后,尽管这可能是处理此问题的最佳方法,但是我当然可以正确地理解它。当我运行代码时,将依次调用每个函数,但在完成前一个函数时不会调用。在第一个功能中,我正在从Firebase下载图像,但是在下载图像之前调用了第二个功能。我已经在代码中删除了细节,但这是到目前为止。
typealias COMPLETION = () -> ()
let functionOne_completion = {
print("functionOne COMPLETED")
}
let functionTwo_completion = {
print("functionTwo COMPLETED")
}
let functionThree_completion = {
print("functionThree COMPLETED")
}
override func viewDidLoad() {
super.viewDidLoad()
let queue = DispatchQueue(label: "com.myApp.myQueue")
queue.sync {
functionOne(completion: functionOne_completion)
functionTwo(completion: functionTwo_completion)
functionThree(completion: functionThree_completion)
}
func functionOne(completion: @escaping COMPLETION) {
print("functionOne STARTED")
completion()
}
func functionTwo(completion: @escaping COMPLETION) {
print("functionTwo STARTED")
completion()
}
func functionThree(completion: @escaping COMPLETION) {
print("functionThree STARTED")
completion()
}
Run Code Online (Sandbox Code Playgroud)