Je veux supprimer les notifications de planification de mon application pour cela J'ai besoin d'un tableau de chaînes pour supprimer les notifications en attente J'ai ce type de chaîne ce n'est pas un tableau de cette chaîne de retour de la base de données fbdb mais je veux le tableau
["01D94B0E-F1AB-421E-9EC3-4A78F0211ED8", "76E16E51-CB59-4D3F-939E-4D492FFB22BE", "97696EBD-252F-4A12-962E-995EF306B557", "84EB98BB-14EB-4D19-83F6-798DCF75E3CD", "B55621AE-B124-4767-8D6E-C728598E5279"]
J'ai ceci est au format Array comment puis-je faire cela? Je sais que c'est une question pour débutant, j'espère que vous vous aiderez
3 Réponses :
Vous pouvez essayer
let str = """
["1","2","3"]
"""
let res = str.dropFirst(1).dropLast(1)
let arr = res.components(separatedBy: ",").map { $0.replacingOccurrences(of: "\"", with: "") }
vous pouvez utiliser JSONDecoder par défaut ...
import Foundation var stringToData: Data? = "[\"01D94B0E-F1AB-421E-9EC3-4A78F0211ED8\", \"76E16E51-CB59-4D3F-939E-4D492FFB22BE\", \"97696EBD-252F-4A12-962E-995EF306B557\", \"84EB98BB-14EB-4D19-83F6-798DCF75E3CD\", \"B55621AE-B124-4767-8D6E-C728598E5279\"]".data(using: .utf8) let decoded = try JSONDecoder().decode(Array<String>.self, from: stringToData!) print(decoded)
sortie:
["01D94B0E-F1AB-421E-9EC3-4A78F0211ED8", "76E16E51-CB59-4D3F -939E-4D492FFB22BE "," 97696EBD-252F-4A12-962E-995EF306B557 "," 84EB98BB-14EB-4D19-83F6-798DCF75E3CD "," B55621AE-B124-4767-8D6E-C984-4767-8D6E "
let str = """["01D94B0E-F1AB-421E-9EC3-4A78F0211ED8", "76E16E51-CB59-4D3F-939E-4D492FFB22BE", "97696EBD-252F-4A12-962E-995EF306B557", "84EB98BB-14EB-4D19-83F6-798DCF75E3CD", "B55621AE-B124-4767-8D6E-C728598E5279"]""" let ids = try? JSONSerialization.jsonObject(with: Data(str.utf8)) as? [String] ?? []