Connection
A path-finding library powered by GameplayKit 👾
Install / Use
/learn @jasonnam/ConnectionREADME
Connection
<p> <img src="https://img.shields.io/badge/swift-5.1-orange.svg" /> <a href="https://github.com/zntfdr/Connection/actions?query=workflow%3A%22Build+%26+Test%22"> <img src="https://img.shields.io/github/workflow/status/zntfdr/Connection/Build & Test?label=CI&logo=GitHub" alt="Build status" /> </a> <a href="https://swift.org/package-manager"> <img src="https://img.shields.io/badge/swiftpm-compatible-brightgreen.svg?style=flat" alt="Swift Package Manager" /> </a> <img src="https://img.shields.io/badge/platforms-macOS+iOS+iPadOS+tvOS-brightgreen.svg?style=flat" alt="MacOS + iOS + iPadOS + tvOS" /> <a href="https://twitter.com/zntfdr"> <img src="https://img.shields.io/badge/twitter-@zntfdr-blue.svg?style=flat" alt="Twitter: @zntfdr" /> </a> </p>Welcome to Connection, a Swift path-finding library. Its primary goal is to extend Apple's GameplayKit framework.
Features
- [x] Weighted connections.
- [x] Total path weight.
- [x] Associated values support.
- [x] Find the shortest path between multiple origins and destinations.
Usage
Connection defines two new generic classes: Node and Graph, which are, respectively, GKGraphNode and GKGraph counterparts.
import Connection
// Create nodes.
let nodeA = Node(value: "A")
let nodeB = Node(value: "B")
let nodeC = Node(value: "C")
// Make connections.
nodeA.addConnection(to: nodeB, bidirectional: false, weight: 1)
nodeB.addConnection(to: nodeC, bidirectional: true, weight: 2)
// Create graph.
let graph = Graph([nodeA, nodeB, nodeC])
// Find path.
let shortestAtoCPath = graph.findPath(from: nodeA, to: nodeC)
print(shortestAtoCPath) // ["A", "B", "C"]
You can find many more examples in the Tests folder.
Installation
Connection is distributed using the Swift Package Manager. To install it into a project, follow this tutorial and use this repository URL: https://github.com/zntfdr/Connection.git.
Credits
Connection was built by Federico Zanetello as a component of Bangkok Metro.
If you'd like to dive deeper into iOS path-finding algorithms, please read this two-part serie:
Contributions and Support
All users are welcome and encouraged to become active participants in the project continued development — by fixing any bug that they encounter, or by improving the documentation wherever it’s found to be lacking.
If you'd like to make a change, please open a Pull Request, even if it just contains a draft of the changes you’re planning, or a test that reproduces an issue.
Thank you and please enjoy using Connection!
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
