gpt4 book ai didi

objective-c - Objective C 到 Swift 的调度过程

转载 作者:行者123 更新时间:2023-11-30 10:01:48 25 4
gpt4 key购买 nike

我在尝试将 Objective C 中的以下代码转换为 Swift 时遇到一些问题:

- (BOOL)loadEventsAtDate:(NSDate*)date
{

dispatch_async(self.bgQueue, ^{
[self bg_loadOneDay];
});

return YES;
}

- (void)bg_loadOneDay
{
__block NSDate *date;

dispatch_sync(dispatch_get_main_queue(), ^{
.....
});

if (date) {
[self bg_loadEventsAtDate:date];
}
}

- (void)bg_loadEventsAtDate:(NSDate*)date
{
dispatch_async(dispatch_get_main_queue(), ^{
......
});
}

你能帮我吗?我对此很陌生!!!提前谢谢你!!!

最佳答案

试试这个:

func loadEventsAtDate(date: NSDate) -> Bool {
let bgQueue = dispatch_queue_create("MY_BG_QUEUE", DISPATCH_QUEUE_SERIAL)//use your `bgQueue`
dispatch_async(bgQueue) {
self.bg_loadOneDay()
}
return true
}

func bg_loadOneDay() {
let date = NSDate()
dispatch_async(dispatch_get_main_queue()) {
//....
}
bg_loadEventsAtDate(date)//not sure which date you are sending here, please check
}

func bg_loadEventsAtDate(date: NSDate) {
dispatch_async(dispatch_get_main_queue()) {
//....
}
}

关于objective-c - Objective C 到 Swift 的调度过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38103181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com