我已经在Firesbase仪表板上设置了所有这些步骤和bundel id,并尝试多次崩溃但没有收到任何报告.
通过以下步骤在模拟器中运行
(IBAction)crashButtonTapped:(id)sender {[[Crashlytics sharedInstance] crash]; }
单击play_arrow Build,然后在Xcode中运行当前方案,以在设备或模拟器上构建您的应用程序.
我想使用满足 OR ( || ) 约束的默认实现来扩展协议。
class A { }
class B { }
protocol SomeProtocol { }
/// It will throw error for ||
extension SomeProtocol where Self: A || Self: B {
}
Run Code Online (Sandbox Code Playgroud) 我正在使用具有QoS背景的串行队列
let serialQueue = DispatchQueue(label: "queue1", qos: DispatchQoS.background)
Run Code Online (Sandbox Code Playgroud)
分配一个作业同步,两个作业异步:
func serialTask() {
serialQueue.sync {
for i in 0..<10 {
print("", i)
}
}
serialQueue.async {
for i in 20..<30 {
print("??", i)
}
}
serialQueue.async {
for i in 101..<120 {
print("", i)
}
}
}
Run Code Online (Sandbox Code Playgroud)
所有3个作业一个接一个地执行同步,但最后两个作业是异步的.同步作业是否在串行队列中同步.
我从Raywenderlich帖子示例中得到了一个带有调度屏障的并发队列
private let concurrentPhotoQueue = DispatchQueue(label: "com.raywenderlich.GooglyPuff.photoQueue", attributes: .concurrent)
写操作在哪里完成
func addPhoto(_ photo: Photo) {
concurrentPhotoQueue.async(flags: .barrier) { [weak self] in
// 1
guard let self = self else {
return
}
// 2
self.unsafePhotos.append(photo)
// 3
DispatchQueue.main.async { [weak self] in
self?.postContentAddedNotification()
}
}
}
Run Code Online (Sandbox Code Playgroud)
虽然读取操作是在
var photos: [Photo] {
var photosCopy: [Photo]!
// 1
concurrentPhotoQueue.sync {
// 2
photosCopy = self.unsafePhotos
}
return photosCopy
}
Run Code Online (Sandbox Code Playgroud)
因为这将解决竞争条件。这里为什么只有Write操作是通过barrier和Read in …
使用SE-0269,我们将\xe2\x80\x99 在下面的情况下不再需要使用显式引用类型。
\nclass Test {\n var x = 0\n func execute(_ work: @escaping () -> Void) {\n work()\n }\n func method() {\n execute { [self] in\n x += 1\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n这是否会处理[weak self]和[unowned self],或者我们应该在该提案中明确使用weak和unowned的情况。
\naddTask()我对 Calling和之间感到困惑addTaskUnlessCancelled。根据定义,addTask()您的组将无条件添加新任务到group
func testCancellation() async {
do {
try await withThrowingTaskGroup(of: Void.self) { group -> Void in
group.addTaskUnlessCancelled {
print("added")
try await Task.sleep(nanoseconds: 1_000_000_000)
throw ExampleError.badURL
}
group.addTaskUnlessCancelled {
print("added")
try await Task.sleep(nanoseconds: 2_000_000_000)
print("Task is cancelled: \(Task.isCancelled)")
}
group.addTaskUnlessCancelled {
print("added")
try await Task.sleep(nanoseconds: 5_000_000_000)
print("Task is cancelled: \(Task.isCancelled)")
}
group.cancelAll()
try await group.next()
}
} catch {
print("Error thrown: \(error.localizedDescription)")
}
}
Run Code Online (Sandbox Code Playgroud)
如果你想避免将任务添加到已取消的组中,我们必须使用该addTaskUnlessCancelled()方法。但即使使用group.cancelAll(),它也会将所有任务添加到组中。true那么这里和仅在Task抛出错误时才返回的返回值有什么区别?
swift ×6
ios ×4
concurrency ×2
async-await ×1
asynchronous ×1
crashlytics ×1
firebase ×1
protocols ×1
semaphore ×1
swift5 ×1