Skip to content

Commit

Permalink
Some documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
trasch committed Jul 12, 2024
1 parent 4edf85d commit 004d356
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Sources/GISTools/GeoJson/GeoJsonCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ extension Coordinate3D: Codable {
// MARK: - SwiftData compatibility (see the README)

#if canImport(SwiftData)

/// A `ValueTransformer` for SwiftData compatibility
/// (see the README for more information/examples).
@objc(GeoJsonTransformer)
public final class GeoJsonTransformer: ValueTransformer {

Expand All @@ -110,14 +113,14 @@ public final class GeoJsonTransformer: ValueTransformer {
true
}

// Encode GeoJSON to Data
/// Encode GeoJSON to Data
public override func transformedValue(_ value: Any?) -> Any? {
guard let geoJson = value as? GeoJson else { return nil }

return geoJson.asJsonData()
}

// Decode Data to GeoJSON
/// Decode Data to GeoJSON
public override func reverseTransformedValue(_ value: Any?) -> Any? {
guard let data = value as? Data else { return nil }

Expand Down
13 changes: 7 additions & 6 deletions Sources/GISTools/GeoJson/GeoJsonConvertible.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Foundation

/// A protocol for GeoJSON objects that can be read from and written to JSON.
/// A protocol for GeoJSON objects that can be read from and written to various datasources.
/// like `URL`s, `Data`, `String`, or any Swift object that looks like GeoJSON.
public protocol GeoJsonConvertible: GeoJsonReadable & GeoJsonWritable {}

// MARK: - GeoJsonReadable

/// A protocol for GeoJSON objects that can be read/parsed from JSON.
/// A protocol for GeoJSON objects that can be read/parsed from any Swift object that looks like GeoJSON.
public protocol GeoJsonReadable {

/// Try to initialize a GeoJSON object from any JSON.
/// Try to initialize a GeoJSON object from anything.
///
/// - important: The source is expected to be in EPSG:4326.
init?(json: Any?)
Expand All @@ -17,7 +18,7 @@ public protocol GeoJsonReadable {

extension GeoJsonReadable {

/// Try to initialize a GeoJSON object from a file.
/// Try to initialize a GeoJSON object from a file/URL.
///
/// - important: The source is expected to be in EPSG:4326.
public init?(contentsOf url: URL) {
Expand Down Expand Up @@ -47,10 +48,10 @@ extension GeoJsonReadable {

// MARK: - GeoJsonWritable

/// A protocol for GeoJSON objects that can write to JSON.
/// A protocol for GeoJSON objects that can write to Swift dictionaries.
public protocol GeoJsonWritable {

/// Return the GeoJson object as Key/Value pairs.
/// Return the GeoJson object as a Swift dictionary.
///
/// - important: Always projected to EPSG:4326, unless the receiver has no SRID.
var asJson: [String: Any] { get }
Expand Down
3 changes: 2 additions & 1 deletion Sources/GISTools/GeoJson/GeoJsonReader.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Foundation

/// A generic helper for creating GeoJSON objects from various datasources.
public enum GeoJsonReader {

/// Try to initialize a GeoJSON object from any JSON.
/// Try to initialize a GeoJSON object from any Swift object.
///
/// - important: The source is expected to be in EPSG:4326.
public static func geoJsonFrom(json: Any?) -> GeoJson? {
Expand Down

0 comments on commit 004d356

Please sign in to comment.