# WriteFreely Swift Package

**URL:** <https://discuss.write.as/t/writefreely-swift-package/1564>\
**Category:** Development\
**Tags:** writefreely\
**Created:** [June 29, 2020, 4:00pm UTC](https://discuss.write.as/t/writefreely-swift-package/1564 "2020-06-29T16:00:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![angelo](https://discuss.write.as/user_avatar/discuss.write.as/angelo/32/884_2.png) [@angelo](https://discuss.write.as/u/angelo)\
**Post date:** [June 29, 2020, 4:00pm UTC](https://discuss.write.as/t/writefreely-swift-package/1564/1 "2020-06-29T16:00:14Z")

</div>

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](https://github.com/writeas/writefreely-swift) 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](https://developers.write.as/docs/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](https://github.com/writeas/writefreely-swift#deployment) — 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:

```auto

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](https://writefreely.org/contribute) 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!

---

<div class="post-metadata">

**Author:** ![angelo](https://discuss.write.as/user_avatar/discuss.write.as/angelo/32/884_2.png) [@angelo](https://discuss.write.as/u/angelo)\
**Post date:** [July 2, 2020, 8:35pm UTC](https://discuss.write.as/t/writefreely-swift-package/1564/2 "2020-07-02T20:35:05Z")

</div>

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](https://github.com/writeas/writefreely-swift/blob/main/docs/WriteFreelyClient.md) should be helpful!

Also, there are a few [open issues](https://github.com/writeas/writefreely-swift/issues) now on GitHub should anyone be interested in [contributing](https://github.com/writeas/writefreely-swift/blob/main/CONTRIBUTING.md)!

---

<div class="post-metadata">

**Author:** ![angelo](https://discuss.write.as/user_avatar/discuss.write.as/angelo/32/884_2.png) [@angelo](https://discuss.write.as/u/angelo)\
**Post date:** [August 17, 2020, 3:02pm UTC](https://discuss.write.as/t/writefreely-swift-package/1564/3 "2020-08-17T15:02:26Z")

</div>

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](https://github.com/writeas/writefreely-swift/pull/14) 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.
