HomeiOS Developmentios - Mannequin Put up doesn't conform to Encodable

ios – Mannequin Put up doesn’t conform to Encodable


I am attempting to implement pagination into my software nevertheless it requires me to adapt my Put up Mannequin to Encodable. I’ve tried studying by means of the docs however I am having a tough time understanding them and I am apprehensive that I might break my code if I mess one thing up. I believed it was as straightforward as including “Encodable” to the properties subsequent the struct title however I used to be incorrect.

My Mannequin is beneath

struct Put up: Identifiable, Decodable, ScrollableData {
    @DocumentID var id: String?
    let caption: String
    let timestamp: Timestamp
    let photoUrl: String
    let uid: String
    var feedback: Int
    var likes: Int
    var replyingTo: String?
    var edited: Bool?
    
    var person: Person?
    var didFavourite: Bool? = false
    var didLike: Bool? = false
    
    var timestampString: String {
        let formatter = DateComponentsFormatter()
        formatter.allowedUnits = [.second, .minute, .hour, .day, .weekOfMonth]
        formatter.maximumUnitCount = 1
        formatter.unitsStyle = .abbreviated
        return formatter.string(from: timestamp.dateValue(), to: Date()) ?? ""
    }
    
    var detailedTimestampString: String {
        let formatter = DateFormatter()
        formatter.dateFormat = "h:mm a · MM/dd/yyyy"
        return formatter.string(from: timestamp.dateValue())
    }
}

Steerage in the appropriate path or assist is very appreciated 🙂

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments