Hello everyone!
I have a problem or I dont understand how i can send my "Section" to an other device.
Here is my "Section" witch I would like to send.
import UIKit
class Section: NSObject, NSCoding {
/
var heading : String
var items : [String]
var foto : [UII
mage]
var beschreibung: [String]
var genre: [String]
var listeZutat: [[String]]
var listeEinheit: [[String]]
var listeMenge: [[Int]]
/
static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
static let ArchiveURL = DocumentsDirectory.appendingPathComponent("sections")
/
struct PropertyKey {
static let headingKey = "heading"
static let itemsKey = "items"
static let fotoKey = "foto"
static let beschreibungKey = "beschreibung"
static let genreKey = "genre"
static let listeZutatKey = "listeZutat"
static let listeEinheitKey = "listeEinheit"
static let listeMengeKey = "listeMenge"
}
init?(heading: String, items : [String], foto : [UIImage], beschreibung: [String], genre: [String], listeZutat: [[String]], listeEinheit: [[String]], listeMenge: [[Int]]) {
self.heading = heading
self.items = items
self.foto = foto
self.beschreibung = beschreibung
self.genre = genre
self.listeMenge = listeMenge
self.listeZutat = listeZutat
self.listeEinheit = listeEinheit
super.init()
}
func encode(with aCoder: NSCoder) {
aCoder.encode(heading, forKey: PropertyKey.headingKey)
aCoder.encode(items, forKey: PropertyKey.itemsKey)
aCoder.encode(genre, forKey: PropertyKey.genreKey)
aCoder.encode(listeZutat, forKey: PropertyKey.listeZutatKey)
aCoder.encode(beschreibung, forKey: PropertyKey.beschreibungKey)
aCoder.encode(listeMenge, forKey: PropertyKey.listeMengeKey)
aCoder.encode(listeEinheit, forKey: PropertyKey.listeEinheitKey)
aCoder.encode(foto, forKey: PropertyKey.fotoKey)
}
required convenience init?(coder aDecoder: NSCoder) {
let heading = aDecoder.decodeObject(forKey: PropertyKey.headingKey) as! String
let items = aDecoder.decodeObject(forKey: PropertyKey.itemsKey) as! [String]
let foto = aDecoder.decodeObject(forKey: PropertyKey.fotoKey) as? [UIImage]
let beschreibung = aDecoder.decodeObject(forKey: PropertyKey.beschreibungKey) as! [String]
let genre = aDecoder.decodeObject(forKey: PropertyKey.genreKey) as! [String]
let listeZutat = aDecoder.decodeObject(forKey: PropertyKey.listeZutatKey) as! [[String]]
let listeMenge = aDecoder.decodeObject(forKey: PropertyKey.listeMengeKey) as! [[Int]]
let listeEinheit = aDecoder.decodeObject(forKey: PropertyKey.listeEinheitKey) as! [[String]]
self.init(heading: heading, items: items, foto: foto!, beschreibung: beschreibung, genre: genre, listeZutat: listeZutat, listeEinheit: listeEinheit, listeMenge: listeMenge)
}
}
I can save and load this "Section" on my iPhone but when I use the "multipeer connectivity" its crash because my Section is not a type data. I dont know how i can convert this...
- Mabye it is better to use an other way to send my "Section2ß
- Is it possible that I can send this with an email??
Thanks you for your help and sorry about my English!🙂