This is a library for creating, manipulating, querying and persisting Graph Data using the Swift programming language. It is written in a functional/immutable style.
Developed and tested on Linux (Ubuntu 16.04) using Swift 3.
The library has basic types for graphs, vertices and edges and uses JSON for persistence.
This project is in its early stages and therefore volatile and likely to change.
import PackageDescription
let package = Package(
name: "Your project/package name",
dependencies: [
.Package(
url: "https://github.com/rudenoise/grift"
majorVersion: 0
)
]
)
import Grift
// create some vertices
let vertexA = Vertex(
name: "Vertex A",
body: "A string..."
)
let vertexB = Vertex(
name: "Vertex B",
body: "Another string..."
)
// create a basic graph, with one edge
if let graphA = Graph(
vertices: [vertexA, vertexB],
edges: [
Edge(
from: vertexA.id,
to: vertexB.id
)
]
) {
// grift uses a failable initializer,
// so wont initailise unless graph is valid
// make a similar graph with another vertex
if let graphB = graphA.addVertex(
Vertex(
name: "Vertex C"
body: "Text again..."
)
) {
// only alows a valid vertex
// make another with a further edge
if let graphC = graphB.addEdge(
Edge(from: vertexB.id, to: vertexA.id)
) {
// etc...
}
}
}
Licensed under GPLv3