-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update README and add logo #3
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a15c7c9
Update README.md
da6e986
Format example
d72cfb1
Format example
a227df8
Update README.md
zenangst 05ab42b
Add logo
02d262c
Update README.md
zenangst 7b2fdf0
Fix typo
zenangst fad6d5a
Update README.md
zenangst 88119a0
Add life hacks
zenangst 0ffdaca
Update README.md
zenangst 29b1cb5
Update README.md
zenangst 1fa4ebb
Update README.md
zenangst 6ea0eac
Update README.md
zenangst adfc7cc
Update README.md
zenangst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,120 @@ | ||
# Compass | ||
![Compass logo](https://raw.githubusercontent.com/hyperoslo/Compass/update/readme/Images/logo_v1.png) | ||
|
||
[![CI Status](http://img.shields.io/travis/hyperoslo/Compass.svg?style=flat)](https://travis-ci.org/hyperoslo/Compass) | ||
[![Version](https://img.shields.io/cocoapods/v/Compass.svg?style=flat)](http://cocoadocs.org/docsets/Compass) | ||
[![License](https://img.shields.io/cocoapods/l/Compass.svg?style=flat)](http://cocoadocs.org/docsets/Compass) | ||
[![Platform](https://img.shields.io/cocoapods/p/Compass.svg?style=flat)](http://cocoadocs.org/docsets/Compass) | ||
|
||
## Usage | ||
Compass helps you setup a central navigation system for your application. | ||
This has many benefits, one of them being that controllers can now be | ||
decoupled, meaning that the list that presents the detail no longer knows | ||
about what its presenting. Controllers become agnostic and views stay | ||
stupid. The user experience stays the same but the logic and separation of | ||
concerns become clearer. The outcome is that your application will become | ||
more modular by default. Anything could potentially be presented from | ||
anywhere, but remember, with great power comes great responsibility. | ||
|
||
## Setup | ||
|
||
#### Step 1 | ||
First you need to register a URL scheme for your application | ||
<img src="https://raw.githubusercontent.com/hyperoslo/Compass/update/readme/Images/setup-url-scheme.png"> | ||
|
||
#### Step 2 | ||
Now you need to configure Compass to use that URL scheme, a good place | ||
to do this is in your `AppDelegate` | ||
```swift | ||
func application(application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | ||
Compass.scheme = "compass" | ||
return true | ||
} | ||
``` | ||
#### Step 3 | ||
Configure your application routes | ||
```swift | ||
func application(application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | ||
Compass.scheme = "compass" | ||
Compass.routes = ["profile:{username}", "login:{username}", "logout"] | ||
return true | ||
} | ||
``` | ||
#### Step 4 | ||
Setup your application to response to the URLs, this can be done in the `AppDelegate` but its up to you to find a more suitable place for it depending on the size of your implementation. | ||
```swift | ||
func application(app: UIApplication, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we have to mention that this func should be used to open a view from outside, but for internal usage it's better to have some global/static function, not to invoke |
||
openURL url: NSURL, | ||
options: [String : AnyObject]) -> Bool { | ||
return Compass.parse(url) { route, arguments in | ||
switch route { | ||
case "profile:{username}": | ||
let profileController = profileController(title: arguments["{username}"]) | ||
self.navigationController?.pushViewController(profileController, | ||
animated: true) | ||
case "login:{username}": | ||
let loginController = LoginController(title: arguments["{username}"]) | ||
self.navigationController?.pushViewController(loginController, | ||
animated: true) | ||
case "logout": | ||
logout() | ||
default: break | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Setting it up this way would mean that | ||
you could open any view from a push notification depending on the contents of the payload. | ||
Preferably you would add your own global function that you use for internal navigation. | ||
|
||
## Compass life hacks | ||
|
||
##### Tip 1. NavigationHandler.swift | ||
You could have multiple handlers depending on if a user is logged in or not. | ||
```swift | ||
<API> | ||
import UIKit | ||
import Compass | ||
|
||
struct NavigationHandler { | ||
static func routePreLogin(route: String, arguments: [String: String], | ||
navigationController: UINavigationController) { | ||
switch route { | ||
case "forgotpassword:{username}": | ||
let forgotPasswordController = ForgotPasswordController(title: arguments["{username}"]) | ||
navigationController?.pushViewController(loginController, | ||
animated: true) | ||
default: break | ||
} | ||
} | ||
|
||
static func routePostLogin(route: String, arguments: [String: String], | ||
navigationController: UINavigationController) { | ||
switch route { | ||
case "profile:{username}": | ||
let profileController = ProfileController(title: arguments["{username}"]) | ||
navigationController?.pushViewController(profileController, | ||
animated: true) | ||
case "logout": | ||
AppDelegate.logout() | ||
default: break | ||
} | ||
} | ||
} | ||
``` | ||
|
||
##### Tip 2. Compass.swift | ||
Add your own global function to easily navigate internally | ||
``` swift | ||
import Compass | ||
|
||
public func navigate(urn: String) { | ||
let stringURL = "\(Compass.scheme)\(urn)" | ||
guard let appDelegate = UIApplication.sharedApplication().delegate as? ApplicationDelegate, | ||
url = NSURL(string: stringURL) else { return } | ||
|
||
appDelegate.handleURL(url) | ||
} | ||
``` | ||
|
||
## Installation | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's better to say that you could present any controller from any place in your app. The list and detail are just a specific example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you already have a line about that below 😄