---
title: "#256: UIPasteboard Revisited 📋"
url: https://littlebitesofcocoa.com/256-uipasteboard-revisited
author: Jake Marsh
date: 2016-08-30
published: 2016-08-30
topics: ["UIKit"]
description: "UIPasteboard is a wonderfully simple little type with a ton of great functionality inside. (Covered previously in Bite #45)."
---

# #256: UIPasteboard Revisited 📋

By Jake Marsh, August 30, 2016. HTML: https://littlebitesofcocoa.com/256-uipasteboard-revisited

_UIPasteboard_ is a wonderfully simple little **type** with a ton of great functionality inside. (Covered previously in [Bite #45](https://www.littlebitesofcocoa.com/45)). Today we'll check out the latest pasteboard improvements in **iOS 10**. Let's begin.

The biggest new user-facing feature of _pasteboards_ in **iOS 10** and **macOS Sierra** is the _Universal Clipboard_. This allows users to copy some content into their _clipboard_ on one device, and retrieve it on another.

We don't need to do anything to get this functionality in our apps. This behavior is on by default for `UIPasteboard.general`, but we can configure how items behave when we add them.

## Expiration Dates

``` swift
let tomorrow = Date().addingTimeInterval(60 * 60 * 24)

UIPasteboard.general.setItems(
  [[ "URL": URL(string: "https://littlebitesofcocoa.com")! ]],
  options: [.expirationDate : tomorrow]
)
```

## Preventing Universal Clipboard

Sometimes there's going to be data that doesn't make sense to sync using the _Universal Clipboard_. This is easy.

``` swift
UIPasteboard.general.setItems(
  [[ "URL": URL(string: "https://littlebitesofcocoa.com")! ]],
  options: [.localOnly : true]
)
```

## has* Properties

Last but not least, _UIPasteboard_ has a few new helper properties for easily checking the current state of a pasteboard:

``` swift
// we can check for images, URLs,
// strings, and colors this way
if pasteboard.hasURLs {
  print(UIPasteboard.general.urls)
}
```
