小编Pau*_*w11的帖子

确认UITextField值的值是枚举的成员

我有一个UITextField随着UIPickerView从一个将其值设置enum和保存按钮,用户按下保存他们的选择.

我的问题是,有没有办法错误陷阱此设置,所以当用户按下保存时,它将确认该值UITextField是我的枚举成员?

我担心的是文本字段留空或粘贴了替代值.

error-handling enums ios swift

0
推荐指数
1
解决办法
149
查看次数

为什么设置为后台的服务质量在主线程中运行?

为什么下面的代码在主线程中运行,虽然我已经为后台线程指定了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/

请参阅"调度队列入门"部分.

multithreading grand-central-dispatch ios swift

0
推荐指数
1
解决办法
764
查看次数

计算待处理的本地通知

我正在尝试编写一个函数来检查是否已达到 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 的初始化值。

我还尝试过其他东西。

-- 一旦我读到这个值,就再次在闭包内设置全局变量,否则将其设置为其原始值

ios localnotification swift

0
推荐指数
1
解决办法
1263
查看次数

如果没有互联网连接,IOS 应用程序会在一行代码上崩溃,我该如何防止这种情况发生

这个代码和它在“尝试!”时崩溃,但我不知道如何捕捉错误并且它是明确的,否则它将无法工作。

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)

crash xcode ios swift

-1
推荐指数
1
解决办法
61
查看次数

Swift:根据键将字典数组转换为String数组

以下是我的字典数组,我希望得到一个基于特定键的字符串数组(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)

swift swift4.2

-3
推荐指数
1
解决办法
118
查看次数

以编程方式在iOS 10上拨打电话,没有提示

我可以在没有提示的情况下通过Objective-C在iOS 10.3.1上的应用程序拨打电话吗?

我试过了

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:xxxxxxxxxxx"]];
Run Code Online (Sandbox Code Playgroud)

但是从应用程序中得到一个承诺 这个

iphone objective-c ios

-8
推荐指数
1
解决办法
2644
查看次数