WriteFreely Swift Package

Hello all! I’m a first-time poster on these forums, and I felt that a nice way to introduce myself would be to bring something to the community. I’ve been working on a WriteFreely Swift package for your Mac and iOS apps, and I’m happy to announce that it’s now in developer preview.

What does the package do?

The short answer is that you use this package in your Mac and iOS apps to work with a WriteFreely service.

The longer answer is that you can do almost all of what the WriteFreely API can do, including:

  • Logging in and out

  • Fetching a User’s Posts and Collections

  • Fetching, creating, and deleting a Collection

  • Fetching, publishing, updating, and deleting a Post

  • Moving a post into a Collection

  • Pinning and unpinning a post from a Collection

  • Fetching the posts in a Collection

What does “developer preview” mean?

“Developer preview” implies that while the framework is functional, there are still rough edges and lots of room for improvement. There’s no test suite (yet), the documentation is underway, and some of the methods are either unimplemented or don’t quite work the way the API endpoints do (notably, the API allows you to pin/unpin an array of posts, but the Swift package works on one at a time).

How do I use this in my Mac or iOS app?

Details are in the README’s Deployment section — essentially, just add the Swift package to your project in Xcode, and then @import WriteFreely in whatever Swift files you use to connect to WriteFreely.

Use public methods on the WriteFreelyClient to send and receive data from the server. The methods leverage completion blocks and the Result type, so you’d call them like so:


func loginHandler(result: (Result<User, Error>)) {

    do {

        let user = try result.get()

        print("Hello, \(user.username)!")

    } catch {

        print(error)

    }

}

guard let instanceURL = URL(string: "https://your.writefreely.host/") else { fatalError() }

let client = WriteFreelyClient(for: instanceURL)

client.login(username: "username", password: "password", completion: loginHandler)

How can I contribute?

There are lots of ways to contribute to this project!

Reporting unexpected behaviour or missing documentation is always helpful, as are discussions around what your needs are for integrating WriteFreely into your apps — this document outlines some of the ways to do so. In short, it’s best to open bug reports on GitHub, and use these forums to discuss features and improvements.

I’m really excited to see what you all build with this. Do share your thoughts below!

1 Like

I just added public API documentation to the /docs folder in the repository. You’ll primarily want to use the WriteFreelyClient class and its methods, so this file should be helpful!

Also, there are a few open issues now on GitHub should anyone be interested in contributing!

Just wanted to give you all a heads up that v0.2.0 of the package will include a breaking change: the custom types in the package will be renamed such that they start with a WF prefix:

  • Collection will become WFCollection
  • Post will become WFPost
  • User will become WFUser
  • WriteFreelyClient will become WFClient
  • WriteFreelyError will become WFError

This improves consistency in naming and also helps to prevent namespace collisions.