Customize handling of asynchronous events by combining event-processing operators using Combine.

Posts under Combine tag

123 Posts

Post

Replies

Boosts

Views

Activity

Compiler error in Xcode 13.0 beta 3 using Combine framework.
In a project that uses the Combine Framework, the following error suddenly occurs: Failed to build module 'Combine'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.5 (swiftlang-1300.0.24.14 clang-1300.0.25.10)', while this compiler is 'Apple Swift version 5.5 (swiftlang-1300.0.24.13 clang-1300.0.25.10)'). Please select a toolchain which matches the SDK. I must confess that I do not understand what the problem is. Is this an Xcode problem or can I solve it myself? Strangely enough, I was able to compile and run the project several times before without any problem. Furthermore, the error is not displayed in my code, but in the package https://github.com/MaxDesiatov/XMLCoder which I included using cocoapods.
1
0
1.9k
Jul ’21
Loading json remotely into SwiftUI ListView
I'm using this documentation as my base https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation I'm failing to understand how I would simply adapt the app to load the json remotely import Foundation var landmarks: [Landmark] = load("landmarkData.json") func load<T: Decodable>(_ filename: String) -> T {     let data: Data     guard let file = Bundle.main.url(forResource: filename, withExtension: nil)         else {             fatalError("Couldn't find \(filename) in main bundle.")     }     do {         data = try Data(contentsOf: file)     } catch {         fatalError("Couldn't load \(filename) from main snippet from Model data.swift the only example I've found is included below, however it's using an entirely different setup and does not use a detail view. import SwiftUI import Combine struct ContentView: View { @ObservedObject var fetcher = MovieFetcher() var body: some View {     VStack {         List(fetcher.movies) { movie in             VStack (alignment: .leading) {                 Text(movie.name)                 Image(movie.thumbnail)                 Text(movie.released)                     .font(.system(size: 11))                     .foregroundColor(Color.gray)             }         }     } } } public class MovieFetcher: ObservableObject { @Published var movies = [Movie]() init(){     load() } func load() {     let url = URL(string: "https://wolvideos.web.app/videos.js")!     URLSession.shared.dataTask(with: url) {(data,response,error) in         do {             if let d = data {                 let decodedLists = try JSONDecoder().decode([Movie].self, from: d)                 DispatchQueue.main.async {                     self.movies = decodedLists                 }             }else {                 print("No Data")             }         } catch {             print ("Error")         }              }.resume()       } } struct Movie: Codable, Identifiable { public var id: Int public var name: String public var thumbnail: String public var released: String enum CodingKeys: String, CodingKey {        case id = "id"        case name = "name"        case thumbnail = "thumbnail"        case released = "description"     } } struct ContentView_Previews: PreviewProvider { static var previews: some View {     ContentView() } } If possible can someone explain how and the best way to load a json file and then let the app format it into detail views?
2
0
2.1k
Jul ’21
DataFlow from Swift to SwfitUI
I have the business logic in Swift class and built UI using SwiftUI. Below the high level code that shows how SwiftUI and its subview receives the data from Swift. Please let me know if its correct approach class SwiftClass{     var score = "1"     func A () {}          func B () {         // score will get updated frequently         let scoreModal =  ScoreUIViewModel()         let scoreUI: ScoreUI = ScoreUI(showModal: .constant(true), scoreUIViewModel: scoreModal)         DispatchQueue.main.async {             scoreUI.displayScoreUI()         }        // score getting updated from another class         scoreModal.score = score // score getting updated from another class         score  = "2"         scoreModal.score = "2" // score getting updated from another class         score  = "3"         scoreModal.score = "3" // score getting updated from another class        score  = "4"         scoreModal.score = "4"      .......              } } import SwiftUI class ScoreUIViewModel: Observable {     @Published score: String } struct ScoreUI: View {     @State var scoreUIViewModel: ScoreUIViewModel     func displayScoreUI() {         let hostController = UIHostingController(rootView: ScoreUI())         hostController = .overCurrentContext         topViewController()!.present(hostController, animated: true, completion: nil)     }.environmentObject(scoreUIViewModel)      } struct ScoreText: View {     @EnvironmentObject var scoreUIViewModel: ScoreUIViewModel     Text(score).foregroundColor(.green) }
3
0
802
Jul ’21
Compiler error in Xcode 13.0 beta 3 using Combine framework.
In a project that uses the Combine Framework, the following error suddenly occurs: Failed to build module 'Combine'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.5 (swiftlang-1300.0.24.14 clang-1300.0.25.10)', while this compiler is 'Apple Swift version 5.5 (swiftlang-1300.0.24.13 clang-1300.0.25.10)'). Please select a toolchain which matches the SDK. I must confess that I do not understand what the problem is. Is this an Xcode problem or can I solve it myself? Strangely enough, I was able to compile and run the project several times before without any problem. Furthermore, the error is not displayed in my code, but in the package https://github.com/MaxDesiatov/XMLCoder which I included using cocoapods.
Replies
1
Boosts
0
Views
1.9k
Activity
Jul ’21
Loading json remotely into SwiftUI ListView
I'm using this documentation as my base https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation I'm failing to understand how I would simply adapt the app to load the json remotely import Foundation var landmarks: [Landmark] = load("landmarkData.json") func load<T: Decodable>(_ filename: String) -> T {     let data: Data     guard let file = Bundle.main.url(forResource: filename, withExtension: nil)         else {             fatalError("Couldn't find \(filename) in main bundle.")     }     do {         data = try Data(contentsOf: file)     } catch {         fatalError("Couldn't load \(filename) from main snippet from Model data.swift the only example I've found is included below, however it's using an entirely different setup and does not use a detail view. import SwiftUI import Combine struct ContentView: View { @ObservedObject var fetcher = MovieFetcher() var body: some View {     VStack {         List(fetcher.movies) { movie in             VStack (alignment: .leading) {                 Text(movie.name)                 Image(movie.thumbnail)                 Text(movie.released)                     .font(.system(size: 11))                     .foregroundColor(Color.gray)             }         }     } } } public class MovieFetcher: ObservableObject { @Published var movies = [Movie]() init(){     load() } func load() {     let url = URL(string: "https://wolvideos.web.app/videos.js")!     URLSession.shared.dataTask(with: url) {(data,response,error) in         do {             if let d = data {                 let decodedLists = try JSONDecoder().decode([Movie].self, from: d)                 DispatchQueue.main.async {                     self.movies = decodedLists                 }             }else {                 print("No Data")             }         } catch {             print ("Error")         }              }.resume()       } } struct Movie: Codable, Identifiable { public var id: Int public var name: String public var thumbnail: String public var released: String enum CodingKeys: String, CodingKey {        case id = "id"        case name = "name"        case thumbnail = "thumbnail"        case released = "description"     } } struct ContentView_Previews: PreviewProvider { static var previews: some View {     ContentView() } } If possible can someone explain how and the best way to load a json file and then let the app format it into detail views?
Replies
2
Boosts
0
Views
2.1k
Activity
Jul ’21
DataFlow from Swift to SwfitUI
I have the business logic in Swift class and built UI using SwiftUI. Below the high level code that shows how SwiftUI and its subview receives the data from Swift. Please let me know if its correct approach class SwiftClass{     var score = "1"     func A () {}          func B () {         // score will get updated frequently         let scoreModal =  ScoreUIViewModel()         let scoreUI: ScoreUI = ScoreUI(showModal: .constant(true), scoreUIViewModel: scoreModal)         DispatchQueue.main.async {             scoreUI.displayScoreUI()         }        // score getting updated from another class         scoreModal.score = score // score getting updated from another class         score  = "2"         scoreModal.score = "2" // score getting updated from another class         score  = "3"         scoreModal.score = "3" // score getting updated from another class        score  = "4"         scoreModal.score = "4"      .......              } } import SwiftUI class ScoreUIViewModel: Observable {     @Published score: String } struct ScoreUI: View {     @State var scoreUIViewModel: ScoreUIViewModel     func displayScoreUI() {         let hostController = UIHostingController(rootView: ScoreUI())         hostController = .overCurrentContext         topViewController()!.present(hostController, animated: true, completion: nil)     }.environmentObject(scoreUIViewModel)      } struct ScoreText: View {     @EnvironmentObject var scoreUIViewModel: ScoreUIViewModel     Text(score).foregroundColor(.green) }
Replies
3
Boosts
0
Views
802
Activity
Jul ’21