Post

Replies

Boosts

Views

Activity

Reply to Please Create a Sendable Version of CKRecord or Make CKRecord Sendable
You can take responsibility for it being Sendable. By default the Sendable protocol is made unavailable to CKRecord. extension CKRecord : @unchecked Sendable { } But these are the supported types that are sendable by default. https://developer.apple.com/documentation/swift/sendable NSFoundation types mention above NSStrings, NSData will not be Sendable but the Swift Foundation types Strings, Data are.
Apr ’23
Reply to Combine AnyCancellable.store(in:) EXC_BAD_ACCESS
Making request async is the issue. This version works without issue in playgrounds: import UIKit import Combine struct User: Codable { let userId: Int let id: Int let title: String let completed: Bool } struct Download { private var cancellables = Set<AnyCancellable>() mutating func request() { URLSession.shared .dataTaskPublisher(for: URL(string: "https://jsonplaceholder.typicode.com/todos/1")!) .map{$0.data} .decode(type: User.self, decoder: JSONDecoder()) .receive(on: DispatchQueue.main) .sink(receiveCompletion: { print ("Received completion: \($0).") }, receiveValue: { data in print(data) }) .store(in: &cancellables) } } var download = Download() download.request() or making request async as follows in playgrounds: import UIKit import Combine struct User: Codable { let userId: Int let id: Int let title: String let completed: Bool } struct Download { private var cancellables = Set<AnyCancellable>() mutating func request() async -> User { return await withCheckedContinuation { continuation in URLSession.shared .dataTaskPublisher(for: URL(string: "https://jsonplaceholder.typicode.com/todos/1")!) .map{$0.data} .decode(type: User.self, decoder: JSONDecoder()) .receive(on: DispatchQueue.main) .sink(receiveCompletion: { print ("Received completion: \($0).") }, receiveValue: { data in continuation.resume(returning: data) }) .store(in: &cancellables) } } } Task { var download = Download() let user = await download.request() print(user) }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’23