michaelgira23 / navigatAR

Finding your way through buildings and campuses through the power of augmented reality
MIT License
56 stars 19 forks source link

Ambiguous reference to member 'decode' #42

Closed Parameshvadivel closed 6 years ago

Parameshvadivel commented 6 years ago

In FirebaseArray - swift complier errors are showing

extension FirebaseArray: Codable { init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() let externalValues = try container.decode([Element: Bool].self)

    values = Array(externalValues.filter { $0.value }.keys)
}

func encode(to encoder: Encoder) throws {
    var container = encoder.singleValueContainer()
    try container.encode(values.reduce(into: [:], { $0[$1] = true }))
}

}

errors are: '<Self, T where Self : SingleValueEncodingContainer, T : Encodable> (inout Self) -> (T) throws -> ()' requires that 'T' conform to 'Encodable' Ambiguous reference to member 'decode'

saramankaramata commented 6 years ago

You copy and paste FirebaseArray.swift file, its work:

//
//  FirebaseArray.swift
//  navigatAR
//
//  Created by Nick Clifford on 2/14/18.
//  Copyright © 2018 MICDS Programming. All rights reserved.
//

struct FirebaseArray<T: Hashable & Codable> {
    typealias ArrayType = [T]

    var values: ArrayType
}

extension FirebaseArray: Collection {
    typealias Element = ArrayType.Element
    typealias Index = ArrayType.Index

    subscript(position: Index) -> Element {
        return values[position]
    }

    var startIndex: Index {
        return values.startIndex
    }

    var endIndex: Index {
        return values.endIndex
    }

    func index(after i: Index) -> Index {
        return i + 1
    }
}

extension FirebaseArray: ExpressibleByArrayLiteral {
    typealias ArrayLiteralElement = Element

    init(arrayLiteral elements: Element...) {
        values = elements
    }
}

extension FirebaseArray: Codable {
    init(from decoder: Decoder) throws {
        let container = try decoder.singleValueContainer()
        let externalValues = try container.decode([Element: Bool].self)

        values = Array(externalValues.filter { $0.value }.keys)
    }

    func encode(to encoder: Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(values.reduce(into: [:], { $0[$1] = true }))
    }
}
michaelgira23 commented 6 years ago

Thank you for your comment @saramankaramata! I've included this fix in https://github.com/michaelgira23/navigatAR/pull/44