小编Eri*_*wig的帖子

我怎么知道UNUserNotificationCenter的removeAllPendingNotificationRequests()何时完成?

iOS文档说UNUserNotificationCenter'removeAllPendingNotificationRequests()是异步的.

我想要做的是:

  1. 打电话removeAllPendingNotificationRequests()去除我所有预定的通知

  2. 安排一堆新通知,其中一些可能会或可能不会具有与之前相同的ID

但是由于文档说该方法是在另一个线程上异步运行(并且没有完成回调参数),我担心有时候,根据线程的变化和时间等因素,第1步仍将是我正在创建第2步中的内容,因此它也会杀死我正在制作的一些新通知.

这种东西手动测试有点棘手,因为它取决于时间.所以我很好奇有人知道这是否是我应该担心的事情......

cocoa-touch ios unusernotificationcenter

15
推荐指数
1
解决办法
328
查看次数

Swift函数作为类中的参数

我是一个快速的初学者,所以要温柔......

我将函数指定为参数时遇到问题.

我已经定义了这个结构:

struct dispatchItem {
   let description: String
   let f: ()->Void

   init(description: String, f: @escaping ()->()) {
      self.description = description
      self.f = f
   }
}
Run Code Online (Sandbox Code Playgroud)

我在一个名为MasterDispatchControllerlike 的类中使用它:

class MasterDispatchController: UITableViewController {

   let dispatchItems = [
      dispatchItem(description: "Static Table", f: testStaticTable),
      dispatchItem(description: "Editable Table", f: testEditableTable)
   ]

    func testEditableTable() {
        //some code
    }

    func testStaticTable() {
        //some code
    }
Run Code Online (Sandbox Code Playgroud)

等等

然后我在我的代码中有一个表视图,它发送到任何被点击的函数(不仅仅是我在上面的代码中显示的两个,但这不重要)就像这样

   override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      dispatchItems[indexPath.row].f()
   }
Run Code Online (Sandbox Code Playgroud)

所以...编译器对此并不满意.它说当我定义dispatchItems let语句时:

无法将类型'(MasterDispatchController) - >() - …

function swift

5
推荐指数
1
解决办法
882
查看次数