Advertisement
jannis6023

Untitled

Dec 10th, 2021
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import Foundation
  3.  
  4. struct NetworkSettings: Codable {
  5.     var ssid: String
  6.     var psk: String
  7. }
  8.  
  9. func getNetworkSettingsFromString(data: String) -> NetworkSettings? {
  10.     let decoder = JSONDecoder()
  11.  
  12.     do{
  13.         return try decoder.decode(NetworkSettings.self, from: data.data(using: .utf8)!)
  14.     }catch{
  15.         print("FEHLER.")
  16.         return nil
  17.     }
  18. }
  19.  
  20. func getNetworkSettingsFromData(data: Data) -> NetworkSettings? {
  21.     let decoder = JSONDecoder()
  22.  
  23.     do{
  24.         return try decoder.decode(NetworkSettings.self, from: data)
  25.     }catch{
  26.         print("FEHLER!")
  27.         return nil
  28.     }
  29. }
  30.  
  31.  
  32. func getJSONfromNetworkSettings(data: NetworkSettings) -> Data?{
  33.     let encoder = JSONEncoder()
  34.     do{
  35.         return try encoder.encode(data)
  36.     }catch{
  37.         return nil
  38.     }
  39. }
  40.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement