Navigation Menu

Skip to content

Commit

Permalink
update docs, add getting started guide
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed Jan 8, 2017
1 parent 9a9b786 commit f300026
Show file tree
Hide file tree
Showing 22 changed files with 614 additions and 217 deletions.
102 changes: 102 additions & 0 deletions Guides/Getting Started.md
@@ -0,0 +1,102 @@
# Getting Started

This guide provides a brief overview for how to get started using `JSQCoreDataKit`.

````swift
import JSQCoreDataKit
````

## Standing up the stack

````swift
// Initialize the Core Data model, this class encapsulates the notion of a .xcdatamodeld file
// The name passed here should be the name of an .xcdatamodeld file
let bundle = Bundle(identifier: "com.MyApp.MyModelFramework")!
let model = CoreDataModel(name: "MyModel", bundle: bundle)

// Initialize a stack with a factory
let factory = CoreDataStackFactory(model: model)

let stack: CoreDataStack?
factory.createStack { (result: StackResult) in
switch result {
case .success(let s):
stack = s

case .failure(let e):
print("Error: \(e)")
}
}
````

## In-memory stacks for testing

````swift
let inMemoryModel = CoreDataModel(name: myName, bundle: myBundle, storeType: .inMemory)
let factory = CoreDataStackFactory(model: inMemoryModel)

let stack: CoreDataStack?
factory.createStack { (result: StackResult) in
switch result {
case .success(let s):
stack = s

case .failure(let e):
print("Error: \(e)")
}
}
````

## Saving a managed object context

````swift
saveContext(stack.mainContext) { result in
switch result {
case .success:
print("save succeeded")

case .failure(let error):
print("save failed: \(error)")
}
}
````

## Deleting the store

````swift
let bundle = Bundle(identifier: "com.MyApp.MyModelFramework")!
let model = CoreDataModel(name: "MyModel", bundle: bundle)
do {
try model.removeExistingStore()
} catch {
print("Error: \(error)")
}
````

## Performing migrations

````swift
let bundle = Bundle(identifier: "com.MyApp.MyModelFramework")!
let model = CoreDataModel(name: "MyModel", bundle: bundle)
if model.needsMigration {
do {
try model.migrate()
} catch {
print("Failed to migrate model: \(error)")
}
}
````

## Using child contexts

````swift
// Create a main queue child context from the main context
let childContext = stack.childContext(concurrencyType: .mainQueueConcurrencyType)

// Create a background queue child context from the background context
let childContext = stack.childContext(concurrencyType: .privateQueueConcurrencyType)
````

## Example app

There's an example app in the `Example/` directory. Open the `ExampleApp.xcodeproj` to run it. The project exercises all basic functionality of the library.
112 changes: 4 additions & 108 deletions README.md
@@ -1,4 +1,5 @@
# JSQCoreDataKit

[![Build Status](https://secure.travis-ci.org/jessesquires/JSQCoreDataKit.svg)](http://travis-ci.org/jessesquires/JSQCoreDataKit) [![Version Status](https://img.shields.io/cocoapods/v/JSQCoreDataKit.svg)][podLink] [![license MIT](https://img.shields.io/cocoapods/l/JSQCoreDataKit.svg)][mitLink] [![codecov](https://codecov.io/gh/jessesquires/JSQCoreDataKit/branch/develop/graph/badge.svg)](https://codecov.io/gh/jessesquires/JSQCoreDataKit) [![Platform](https://img.shields.io/cocoapods/p/JSQCoreDataKit.svg)][docsLink] [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)

*A swifter Core Data stack*
Expand Down Expand Up @@ -39,10 +40,10 @@ This library aims to do the following:
````ruby
use_frameworks!

# For latest release in cocoapods
# Latest release in CocoaPods
pod 'JSQCoreDataKit'

# Feeling adventurous? Get the latest on develop
# Latest on develop branch
pod 'JSQCoreDataKit', :git => 'https://github.com/jessesquires/JSQCoreDataKit.git', :branch => 'develop'
````

Expand All @@ -54,7 +55,7 @@ github "jessesquires/JSQCoreDataKit"

## Documentation

Read the [docs][docsLink]. Generated with [jazzy](https://github.com/realm/jazzy). Hosted by [GitHub Pages](https://pages.github.com).
Read the [docs][docsLink]. Generated with [jazzy](https://github.com/realm/jazzy). Hosted by [GitHub Pages](https://pages.github.com).

#### Generate

Expand All @@ -68,111 +69,6 @@ $ ./build_docs.sh
$ open index.html -a Safari
````

## Getting Started

````swift
import JSQCoreDataKit
````

#### Standing up the stack

````swift
// Initialize the Core Data model, this class encapsulates the notion of a .xcdatamodeld file
// The name passed here should be the name of an .xcdatamodeld file
let bundle = Bundle(identifier: "com.MyApp.MyModelFramework")!
let model = CoreDataModel(name: "MyModel", bundle: bundle)

// Initialize a stack with a factory
let factory = CoreDataStackFactory(model: model)

let stack: CoreDataStack?
factory.createStack { (result: StackResult) in
switch result {
case .success(let s):
stack = s

case .failure(let e):
print("Error: \(e)")
}
}
````

#### In-memory stacks for testing

````swift
let inMemoryModel = CoreDataModel(name: myName, bundle: myBundle, storeType: .inMemory)
let factory = CoreDataStackFactory(model: inMemoryModel)

let stack: CoreDataStack?
factory.createStack { (result: StackResult) in
switch result {
case .success(let s):
stack = s

case .failure(let e):
print("Error: \(e)")
}
}
````

#### Saving a managed object context

````swift
saveContext(stack.mainContext) { result in
switch result {
case .success:
print("save succeeded")

case .failure(let error):
print("save failed: \(error)")
}
}
````

#### Deleting the store

````swift
let bundle = Bundle(identifier: "com.MyApp.MyModelFramework")!
let model = CoreDataModel(name: "MyModel", bundle: bundle)
do {
try model.removeExistingStore()
} catch {
print("Error: \(error)")
}
````

#### Performing migrations

````swift
let bundle = Bundle(identifier: "com.MyApp.MyModelFramework")!
let model = CoreDataModel(name: "MyModel", bundle: bundle)
if model.needsMigration {
do {
try model.migrate()
} catch {
print("Failed to migrate model: \(error)")
}
}
````

#### Using child contexts

````swift
// Create a main queue child context from the main context
let childContext = stack.childContext(concurrencyType: .mainQueueConcurrencyType)

// Create a background queue child context from the background context
let childContext = stack.childContext(concurrencyType: .privateQueueConcurrencyType)
````

## Example app

There's an example app in the `Example/` directory. Open the `ExampleApp.xcodeproj` to run it. The project exercises all basic functionality of the library.

## Unit tests

There's a suite of unit tests for `JSQCoreDataKit.framework`. You can run them in the usual way from Xcode by opening `JSQCoreDataKit.xcodeproj`. These tests are well commented and serve as further documentation for how to use this library.

## Contribute

Please follow these sweet [contribution guidelines](https://github.com/jessesquires/HowToContribute).
Expand Down
17 changes: 10 additions & 7 deletions build_docs.sh
Expand Up @@ -4,10 +4,13 @@
# https://github.com/realm/jazzy
# ------------------------------

jazzy -o docs/ \
--source-directory . \
--readme README.md \
-a 'Jesse Squires' \
-u 'https://twitter.com/jesse_squires' \
-m 'JSQCoreDataKit' \
-g 'https://github.com/jessesquires/JSQCoreDataKit'
jazzy \
--clean \
--author 'Jesse Squires' \
--author_url 'https://twitter.com/jesse_squires' \
--github_url 'https://github.com/jessesquires/JSQCoreDataKit' \
--module 'JSQCoreDataKit' \
--source-directory . \
--readme 'README.md' \
--documentation 'Guides/*.md' \
--output docs/ \
10 changes: 9 additions & 1 deletion docs/Classes.html
Expand Up @@ -27,6 +27,14 @@
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="Guides.html">Guides</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="getting-started.html">Getting Started</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Classes.html">Classes</a>
<ul class="nav-group-tasks">
Expand Down Expand Up @@ -159,7 +167,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2017 <a class="link" href="https://twitter.com/jesse_squires" target="_blank" rel="external">Jesse Squires</a>. All rights reserved. (Last updated: 2017-01-03)</p>
<p>&copy; 2017 <a class="link" href="https://twitter.com/jesse_squires" target="_blank" rel="external">Jesse Squires</a>. All rights reserved. (Last updated: 2017-01-08)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.3</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
10 changes: 9 additions & 1 deletion docs/Classes/CoreDataStack.html
Expand Up @@ -28,6 +28,14 @@
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="../Guides.html">Guides</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../getting-started.html">Getting Started</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Classes.html">Classes</a>
<ul class="nav-group-tasks">
Expand Down Expand Up @@ -410,7 +418,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2017 <a class="link" href="https://twitter.com/jesse_squires" target="_blank" rel="external">Jesse Squires</a>. All rights reserved. (Last updated: 2017-01-03)</p>
<p>&copy; 2017 <a class="link" href="https://twitter.com/jesse_squires" target="_blank" rel="external">Jesse Squires</a>. All rights reserved. (Last updated: 2017-01-08)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.3</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
10 changes: 9 additions & 1 deletion docs/Enums.html
Expand Up @@ -27,6 +27,14 @@
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="Guides.html">Guides</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="getting-started.html">Getting Started</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Classes.html">Classes</a>
<ul class="nav-group-tasks">
Expand Down Expand Up @@ -276,7 +284,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2017 <a class="link" href="https://twitter.com/jesse_squires" target="_blank" rel="external">Jesse Squires</a>. All rights reserved. (Last updated: 2017-01-03)</p>
<p>&copy; 2017 <a class="link" href="https://twitter.com/jesse_squires" target="_blank" rel="external">Jesse Squires</a>. All rights reserved. (Last updated: 2017-01-08)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.3</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
10 changes: 9 additions & 1 deletion docs/Enums/MigrationError.html
Expand Up @@ -28,6 +28,14 @@
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="../Guides.html">Guides</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../getting-started.html">Getting Started</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Classes.html">Classes</a>
<ul class="nav-group-tasks">
Expand Down Expand Up @@ -223,7 +231,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2017 <a class="link" href="https://twitter.com/jesse_squires" target="_blank" rel="external">Jesse Squires</a>. All rights reserved. (Last updated: 2017-01-03)</p>
<p>&copy; 2017 <a class="link" href="https://twitter.com/jesse_squires" target="_blank" rel="external">Jesse Squires</a>. All rights reserved. (Last updated: 2017-01-08)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.3</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
10 changes: 9 additions & 1 deletion docs/Enums/ModelFileExtension.html
Expand Up @@ -28,6 +28,14 @@
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="../Guides.html">Guides</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../getting-started.html">Getting Started</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Classes.html">Classes</a>
<ul class="nav-group-tasks">
Expand Down Expand Up @@ -247,7 +255,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2017 <a class="link" href="https://twitter.com/jesse_squires" target="_blank" rel="external">Jesse Squires</a>. All rights reserved. (Last updated: 2017-01-03)</p>
<p>&copy; 2017 <a class="link" href="https://twitter.com/jesse_squires" target="_blank" rel="external">Jesse Squires</a>. All rights reserved. (Last updated: 2017-01-08)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.3</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down

0 comments on commit f300026

Please sign in to comment.