Campus

public enum Campus

Helper type for accessing a list of all building complexes.

  • Fetch all building complexes.

    Declaration

    Swift

    public static func fetch(session: URLSession = .shared,
                                 rawDataHandler: ((Data) -> Void)? = nil,
                                 completion: @escaping (Result<[BuildingComplex]>) -> Void)

    Parameters

    session

    session to use, defaults to .shared

    rawDataHandler

    receives the raw data before being parsed

    completion

    handler

  • Fetch all building complexes if the current data hash differs from the given one.

    Warning

    Completion handler is only called on error or if newer data was found.

    Declaration

    Swift

    public static func fetch(ifNewerThanHash oldHash: String,
                                 session: URLSession = .shared,
                                 rawDataHandler: ((Data) -> Void)? = nil,
                                 completion: @escaping (Result<[BuildingComplex]>) -> Void)

    Parameters

    oldHash

    given data hash

    session

    session to use, defaults to .shared

    rawDataHandler

    receives the raw data before being parsed

    completion

    handler

  • Decode a list of BuildingComplex‘es from given data. This takes the data returned by m/json_gebaeude/all, which is the same as Campus.fetch(). Use this to provide initial data to be used if an internet connection is not present for the first start or if persisting the API responses directly.

    Throws

    any errors occurring during JSON decoding

    Declaration

    Swift

    public static func readFromLocal(data: Data) throws -> [BuildingComplex]

    Parameters

    data

    API response as data

    Return Value

    decoded API response