我有一个UITextField随着UIPickerView从一个将其值设置enum和保存按钮,用户按下保存他们的选择.
我的问题是,有没有办法错误陷阱此设置,所以当用户按下保存时,它将确认该值UITextField是我的枚举成员?
我担心的是文本字段留空或粘贴了替代值.
为什么下面的代码在主线程中运行,虽然我已经为后台线程指定了qos?
func testQueue(){
let queue = DispatchQueue(label: "com.appcoda.myqueue",qos:.background)
queue.sync {
if Thread.isMainThread{
print("is in main thread")
}else{
print("is i background thread")
}
for i in 100..<110 {
print("??", i)
}
}
}
testQueue()
Run Code Online (Sandbox Code Playgroud)
每当我尝试运行该方法时,我会在控制台中获取msg is in main thread,但不应该是这种情况.我正在阅读本文.
http://www.appcoda.com/grand-central-dispatch/
请参阅"调度队列入门"部分.
我正在尝试编写一个函数来检查是否已达到 64 个本地通知的限制。有一些处理 UIlocalNotifications 的答案,但我还没有找到 NSlocalNotifications 的答案。这是我的功能
func notificationLimitreached() {
let center = UNUserNotificationCenter.current()
var limit = false
center.getPendingNotificationRequests(completionHandler: { requests in
print(requests.count)
if requests.count > 59 {
limit = true
print(limit)
} else {
limit = false
}
})
print (limit)
Run Code Online (Sandbox Code Playgroud)
问题是“limit”变量在闭包内打印 true,然后在离开闭包后重置为 false 的初始化值。
我还尝试过其他东西。
-- 一旦我读到这个值,就再次在闭包内设置全局变量,否则将其设置为其原始值
这个代码和它在“尝试!”时崩溃,但我不知道如何捕捉错误并且它是明确的,否则它将无法工作。
func downloadPicture2(finished: () -> Void) {
let imageUrlString = self.payments[indexPath.row].picture
let imageUrl = URL(string: imageUrlString!)!
let imageData = try! Data(contentsOf: imageUrl)
cell.profilePicture.image = UIImage(data: imageData)
cell.profilePicture.layer.cornerRadius = cell.profilePicture.frame.size.width / 2
cell.profilePicture.clipsToBounds = true
}
Run Code Online (Sandbox Code Playgroud) 以下是我的字典数组,我希望得到一个基于特定键的字符串数组(contentURL在我的情况下是键).
我怎样才能实现它?我曾经碰到Reduce&Filter但没有一个适合我的要求.
(
{
contentURL = "https://d1shcqlf263trc.cloudfront.net/1510232473240ab.mp4";
},
{
contentURL = "https://d1shcqlf263trc.cloudfront.net/151021804847312.mp4";
},
{
contentURL = "https://d1shcqlf263trc.cloudfront.net/151021536556612.mp4";
},
{
contentURL = "https://d1shcqlf263trc.cloudfront.net/151021528690312.mp4";
}
)
Run Code Online (Sandbox Code Playgroud)
预期产出
[
"https://d1shcqlf263trc.cloudfront.net/1510232473240ab.mp4",
"https://d1shcqlf263trc.cloudfront.net/151021804847312.mp4",
"https://d1shcqlf263trc.cloudfront.net/151021536556612.mp4",
"https://d1shcqlf263trc.cloudfront.net/151021528690312.mp4"
]
Run Code Online (Sandbox Code Playgroud) 我可以在没有提示的情况下通过Objective-C在iOS 10.3.1上的应用程序拨打电话吗?
我试过了
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:xxxxxxxxxxx"]];
Run Code Online (Sandbox Code Playgroud)
但是从应用程序中得到一个承诺
