---
title: "#227: Convert Markdown to NSAttributedStrings with SwiftyMarkdown 📝"
url: https://littlebitesofcocoa.com/227-convert-markdown-to-nsattributedstrings-with-swiftymarkdown
author: Jake Marsh
published: 2016-04-05
topics: ["Libraries","Foundation"]
description: "Markdown is awesome. For those not familiar, read up on why Markdown is awesome in this fantastic post by Brett Terpstra."
---

# #227: Convert Markdown to NSAttributedStrings with SwiftyMarkdown 📝

By Jake Marsh, April 5, 2016. HTML: https://littlebitesofcocoa.com/227-convert-markdown-to-nsattributedstrings-with-swiftymarkdown

[Markdown](https://daringfireball.net/projects/markdown/) is awesome. For those not familiar, read up on [why Markdown is awesome in this fantastic post](http://brettterpstra.com/2011/08/31/why-markdown-a-two-minute-explanation/) by [Brett Terpstra](https://twitter.com/ttscoff).

When it comes to using _Markdown_ on iOS and OS X, there's tons of options. Today we'll look at one popular solution from [Simon Fairbairn](https://github.com/SimonFairbairn) called [SwiftyMarkdown](https://github.com/SimonFairbairn/SwiftyMarkdown). It helps us translate **Swift Strings** containing _Markdown_ into *NSAttributedStrings*. Let's take a look.

``` swift
let md = SwiftyMarkdown(string: "# SwiftyMarkdown\nConverts *Markdown* files and strings into NSAttributedString")
md.attributedString()
```

It's that simple! SwiftyMarkdown will use some defaults for fonts, colors, etc. Customizing those is quite simple:

``` swift
md.body.fontName = "AvenirNextCondensed-Medium"

md.h1.color = UIColor.redColor()
md.h1.fontName = "AvenirNextCondensed-Bold"

md.italic.color = UIColor.blueColor()
```

We can supply custom colors and fonts for each different tag, [SwiftyMarkdown](https://github.com/SimonFairbairn/SwiftyMarkdown) even supports inline links, neat!

More info about _SwiftyMarkdown_ can be found at [git.io/swiftymarkdown](https://git.io/swiftymarkdown)
