Post

Replies

Boosts

Views

Activity

Reply to Error JSONSerialization
I am facing similar issue.... Error: underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.} Question I know that using using JSONDecoder we can convert the downloaded JSON data into class/struct object. Is there a way to do the same for raw data(NSData)/octect. Since downloaded is not a json, I am getting error. I have class like this Code public struct FileData: Codable{ public var data: Data? public init (data: Data? = nil){ self.data = data } } Is there a way to assign the downloaded data to FileData().data via decoding extension Data { func decode() -> Result<T, Error> where T: Codable { do { let decoder = JSONDecoder() let object: T = try decoder.decode(T.self, from: self)  return Result.success(object) } catch { return Result.failure(error) } } Expectation: Here T is FileData. I using REST Get api to download(octet stream) a file data and want to set it to FileData().data. It seems like raw data can't be Codable? Is that true? If so, I think I need to manually assign the downloaded data to FileData().data
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to Present SwiftUI without tap
let swiftUIController = UIHostingController(rootView: ContentView(showModal: .constant(true))) rootController()!.present(swiftUIController, animated: true, completion: nil) Above code works but not sure whether its a best practice.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to Pass Data from Swift to SwifUI
This is how I ended up.     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) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to Swift framework localization
Yes, comment parameter is for the development purpose. In the app UI, I see text as "string_key" Localizable.Strings contents will look like below */    Localizable.strings */ "string_key" = "username"; "string_key1" = "password"; "string_key2" = "login";**
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’21