Skip to content

Commit

Permalink
Merge pull request #31 from coshx/zealous-hornet
Browse files Browse the repository at this point in the history
Zealous hornet release
  • Loading branch information
acadet committed Nov 30, 2015
2 parents 134e303 + a92fe2f commit c090de8
Show file tree
Hide file tree
Showing 47 changed files with 1,502 additions and 691 deletions.
4 changes: 2 additions & 2 deletions Caravel.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
# summary should be tweet-length, and the description more in depth.
#

version = "0.4.4"
version = "1.0.0"

s.name = "Caravel"
s.version = version
Expand Down Expand Up @@ -62,7 +62,7 @@ Pod::Spec.new do |s|
#

# s.platform = :ios
s.platform = :ios, "8.0"
s.platform = :ios, "8.1"

# When using multiple platforms
# s.ios.deployment_target = "5.0"
Expand Down
78 changes: 51 additions & 27 deletions Caravel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
objects = {

/* Begin PBXBuildFile section */
A7199EEA1BFC038D00757E4F /* CaravelError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7199EE91BFC038D00757E4F /* CaravelError.swift */; };
A7199EEC1BFC0EC700757E4F /* CaravelFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7199EEB1BFC0EC700757E4F /* CaravelFactory.swift */; };
A7199EEE1BFC11E000757E4F /* NSObjectExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7199EED1BFC11E000757E4F /* NSObjectExtension.swift */; };
A7199EF01BFC134B00757E4F /* ThreadingHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7199EEF1BFC134B00757E4F /* ThreadingHelper.swift */; };
A7199EF31BFC1F4400757E4F /* EventBus.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7199EF21BFC1F4400757E4F /* EventBus.swift */; };
A7AC9F281B3493EB0041EB0B /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7AC9F271B3493EB0041EB0B /* StringExtension.swift */; };
A7F1DD981B17D957001E9B94 /* caravel.h in Headers */ = {isa = PBXBuildFile; fileRef = A7F1DD971B17D957001E9B94 /* caravel.h */; settings = {ATTRIBUTES = (Public, ); }; };
A7F1DD9E1B17D958001E9B94 /* Caravel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7F1DD921B17D957001E9B94 /* Caravel.framework */; };
A7F1DDA51B17D958001E9B94 /* caravelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDA41B17D958001E9B94 /* caravelTests.swift */; };
A7F1DDB21B17D989001E9B94 /* Caravel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDAE1B17D989001E9B94 /* Caravel.swift */; };
A7F1DDB31B17D989001E9B94 /* Subscriber.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDAF1B17D989001E9B94 /* Subscriber.swift */; };
A7F1DDB31B17D989001E9B94 /* EventSubscriber.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDAF1B17D989001E9B94 /* EventSubscriber.swift */; };
A7F1DDB51B17D989001E9B94 /* UIWebViewDelegateMediator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDB11B17D989001E9B94 /* UIWebViewDelegateMediator.swift */; };
A7F1DDB81B17E5F8001E9B94 /* DataSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDB71B17E5F8001E9B94 /* DataSerializer.swift */; };
A7F1DDBA1B17E6F5001E9B94 /* SupportedType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDB91B17E6F5001E9B94 /* SupportedType.swift */; };
A7F1DDBC1B17EF24001E9B94 /* ArgumentParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDBB1B17EF24001E9B94 /* ArgumentParser.swift */; };
/* End PBXBuildFile section */

Expand All @@ -30,6 +34,11 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
A7199EE91BFC038D00757E4F /* CaravelError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaravelError.swift; sourceTree = "<group>"; };
A7199EEB1BFC0EC700757E4F /* CaravelFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CaravelFactory.swift; path = internal/CaravelFactory.swift; sourceTree = "<group>"; };
A7199EED1BFC11E000757E4F /* NSObjectExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NSObjectExtension.swift; path = utils/NSObjectExtension.swift; sourceTree = "<group>"; };
A7199EEF1BFC134B00757E4F /* ThreadingHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ThreadingHelper.swift; path = utils/ThreadingHelper.swift; sourceTree = "<group>"; };
A7199EF21BFC1F4400757E4F /* EventBus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventBus.swift; sourceTree = "<group>"; };
A7AC9F271B3493EB0041EB0B /* StringExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StringExtension.swift; path = utils/StringExtension.swift; sourceTree = "<group>"; };
A7F1DD921B17D957001E9B94 /* Caravel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Caravel.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A7F1DD961B17D957001E9B94 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -38,11 +47,10 @@
A7F1DDA31B17D958001E9B94 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A7F1DDA41B17D958001E9B94 /* caravelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = caravelTests.swift; sourceTree = "<group>"; };
A7F1DDAE1B17D989001E9B94 /* Caravel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Caravel.swift; sourceTree = "<group>"; };
A7F1DDAF1B17D989001E9B94 /* Subscriber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Subscriber.swift; sourceTree = "<group>"; };
A7F1DDB11B17D989001E9B94 /* UIWebViewDelegateMediator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIWebViewDelegateMediator.swift; sourceTree = "<group>"; };
A7F1DDB71B17E5F8001E9B94 /* DataSerializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataSerializer.swift; sourceTree = "<group>"; };
A7F1DDB91B17E6F5001E9B94 /* SupportedType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SupportedType.swift; sourceTree = "<group>"; };
A7F1DDBB1B17EF24001E9B94 /* ArgumentParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArgumentParser.swift; sourceTree = "<group>"; };
A7F1DDAF1B17D989001E9B94 /* EventSubscriber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EventSubscriber.swift; path = internal/EventSubscriber.swift; sourceTree = "<group>"; };
A7F1DDB11B17D989001E9B94 /* UIWebViewDelegateMediator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIWebViewDelegateMediator.swift; path = internal/UIWebViewDelegateMediator.swift; sourceTree = "<group>"; };
A7F1DDB71B17E5F8001E9B94 /* DataSerializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DataSerializer.swift; path = internal/DataSerializer.swift; sourceTree = "<group>"; };
A7F1DDBB1B17EF24001E9B94 /* ArgumentParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ArgumentParser.swift; path = internal/ArgumentParser.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -64,10 +72,24 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
A7199EF11BFC1EBE00757E4F /* internal */ = {
isa = PBXGroup;
children = (
A7F1DDBB1B17EF24001E9B94 /* ArgumentParser.swift */,
A7199EEB1BFC0EC700757E4F /* CaravelFactory.swift */,
A7F1DDB71B17E5F8001E9B94 /* DataSerializer.swift */,
A7F1DDAF1B17D989001E9B94 /* EventSubscriber.swift */,
A7F1DDB11B17D989001E9B94 /* UIWebViewDelegateMediator.swift */,
);
name = internal;
sourceTree = "<group>";
};
A7AC9F261B3493CA0041EB0B /* utils */ = {
isa = PBXGroup;
children = (
A7AC9F271B3493EB0041EB0B /* StringExtension.swift */,
A7199EED1BFC11E000757E4F /* NSObjectExtension.swift */,
A7199EEF1BFC134B00757E4F /* ThreadingHelper.swift */,
);
name = utils;
sourceTree = "<group>";
Expand All @@ -93,15 +115,13 @@
A7F1DD941B17D957001E9B94 /* caravel */ = {
isa = PBXGroup;
children = (
A7AC9F261B3493CA0041EB0B /* utils */,
A7F1DDAE1B17D989001E9B94 /* Caravel.swift */,
A7F1DDAF1B17D989001E9B94 /* Subscriber.swift */,
A7F1DDB11B17D989001E9B94 /* UIWebViewDelegateMediator.swift */,
A7F1DD971B17D957001E9B94 /* caravel.h */,
A7F1DDAE1B17D989001E9B94 /* Caravel.swift */,
A7199EE91BFC038D00757E4F /* CaravelError.swift */,
A7199EF21BFC1F4400757E4F /* EventBus.swift */,
A7199EF11BFC1EBE00757E4F /* internal */,
A7F1DD951B17D957001E9B94 /* Supporting Files */,
A7F1DDB71B17E5F8001E9B94 /* DataSerializer.swift */,
A7F1DDB91B17E6F5001E9B94 /* SupportedType.swift */,
A7F1DDBB1B17EF24001E9B94 /* ArgumentParser.swift */,
A7AC9F261B3493CA0041EB0B /* utils */,
);
path = caravel;
sourceTree = "<group>";
Expand Down Expand Up @@ -145,9 +165,9 @@
/* End PBXHeadersBuildPhase section */

/* Begin PBXNativeTarget section */
A7F1DD911B17D957001E9B94 /* Caravel.temp_caseinsensitive_rename */ = {
A7F1DD911B17D957001E9B94 /* Caravel */ = {
isa = PBXNativeTarget;
buildConfigurationList = A7F1DDA81B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel.temp_caseinsensitive_rename" */;
buildConfigurationList = A7F1DDA81B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel" */;
buildPhases = (
A7F1DD8D1B17D957001E9B94 /* Sources */,
A7F1DD8E1B17D957001E9B94 /* Frameworks */,
Expand All @@ -158,14 +178,14 @@
);
dependencies = (
);
name = Caravel.temp_caseinsensitive_rename;
name = Caravel;
productName = caravel;
productReference = A7F1DD921B17D957001E9B94 /* Caravel.framework */;
productType = "com.apple.product-type.framework";
};
A7F1DD9C1B17D958001E9B94 /* Caravel.temp_caseinsensitive_renameTests */ = {
A7F1DD9C1B17D958001E9B94 /* CaravelTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = A7F1DDAB1B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel.temp_caseinsensitive_renameTests" */;
buildConfigurationList = A7F1DDAB1B17D958001E9B94 /* Build configuration list for PBXNativeTarget "CaravelTests" */;
buildPhases = (
A7F1DD991B17D958001E9B94 /* Sources */,
A7F1DD9A1B17D958001E9B94 /* Frameworks */,
Expand All @@ -176,7 +196,7 @@
dependencies = (
A7F1DDA01B17D958001E9B94 /* PBXTargetDependency */,
);
name = Caravel.temp_caseinsensitive_renameTests;
name = CaravelTests;
productName = caravelTests;
productReference = A7F1DD9D1B17D958001E9B94 /* CaravelTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
Expand Down Expand Up @@ -212,8 +232,8 @@
projectDirPath = "";
projectRoot = "";
targets = (
A7F1DD911B17D957001E9B94 /* Caravel.temp_caseinsensitive_rename */,
A7F1DD9C1B17D958001E9B94 /* Caravel.temp_caseinsensitive_renameTests */,
A7F1DD911B17D957001E9B94 /* Caravel */,
A7F1DD9C1B17D958001E9B94 /* CaravelTests */,
);
};
/* End PBXProject section */
Expand All @@ -240,12 +260,16 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A7F1DDB31B17D989001E9B94 /* Subscriber.swift in Sources */,
A7F1DDB31B17D989001E9B94 /* EventSubscriber.swift in Sources */,
A7199EF31BFC1F4400757E4F /* EventBus.swift in Sources */,
A7AC9F281B3493EB0041EB0B /* StringExtension.swift in Sources */,
A7199EF01BFC134B00757E4F /* ThreadingHelper.swift in Sources */,
A7F1DDB51B17D989001E9B94 /* UIWebViewDelegateMediator.swift in Sources */,
A7F1DDBA1B17E6F5001E9B94 /* SupportedType.swift in Sources */,
A7F1DDB81B17E5F8001E9B94 /* DataSerializer.swift in Sources */,
A7199EEA1BFC038D00757E4F /* CaravelError.swift in Sources */,
A7199EEC1BFC0EC700757E4F /* CaravelFactory.swift in Sources */,
A7F1DDB21B17D989001E9B94 /* Caravel.swift in Sources */,
A7199EEE1BFC11E000757E4F /* NSObjectExtension.swift in Sources */,
A7F1DDBC1B17EF24001E9B94 /* ArgumentParser.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -263,7 +287,7 @@
/* Begin PBXTargetDependency section */
A7F1DDA01B17D958001E9B94 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = A7F1DD911B17D957001E9B94 /* Caravel.temp_caseinsensitive_rename */;
target = A7F1DD911B17D957001E9B94 /* Caravel */;
targetProxy = A7F1DD9F1B17D958001E9B94 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
Expand Down Expand Up @@ -433,7 +457,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
A7F1DDA81B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel.temp_caseinsensitive_rename" */ = {
A7F1DDA81B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A7F1DDA91B17D958001E9B94 /* Debug */,
Expand All @@ -442,7 +466,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
A7F1DDAB1B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel.temp_caseinsensitive_renameTests" */ = {
A7F1DDAB1B17D958001E9B94 /* Build configuration list for PBXNativeTarget "CaravelTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A7F1DDAC1B17D958001E9B94 /* Debug */,
Expand Down
121 changes: 25 additions & 96 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Caravel
![Caravel Logo](logo.png)

[![CocoaPods](https://img.shields.io/cocoapods/v/Caravel.svg?style=flat-square)](https://cocoapods.org/pods/Caravel)

Expand All @@ -8,21 +8,21 @@

## Features

* Easy event bus system
* Easy, fast and reliable event bus system
* Multiple bus support
* `When Ready` event: do not miss any event from your lovely Swift controller!
* Multithreading support
* iOS ~> JavaScript supported types:
- `Bool`
- `Int`
- `Float`
- `Double`
- `String`
- `NSArray`
- `NSDictionary`
- Any array (using types in this list)
- Any dictionary (using types in this list)
* JavaScript ~> iOS supported types:
- `Bool`
- `Boolean`
- `Int`
- `Double`
- `Float`
- `String`
- `Array` (available as a `NSArray`)
- `Object` (available as a `NSDictionary`)
Expand All @@ -43,26 +43,33 @@ Once done, you should find a `caravel.min.js` file in either the Pod or the subm
<script type="text/javascript" src="caravel.min.js"></script>
```

## Migrate from 0.* to 1.*

[Please glance at this blog post](http://www.coshx.com/blog/2015/11/19/releasing-caravel-1-0-0/).

## Get started

Caravel allows developers to communicate between their `UIWebView` and the embedded JS. You can send any kind of message between those two folks.

Have a glance at this super simple sample. Let's start with the iOS part:

```swift
import Caravel

class MyController: UIViewController {
@IBOutlet weak var webView: UIWebView!

func viewDidLoad() {
super.viewDidLoad()

Caravel.getDefault().whenReady() { bus in
bus.post("AnEvent", anArray: [1, 2, 3])
}
// Prepare your bus before loading your web view's content
Caravel.getDefault(self, webView: webView, whenReady: { bus in
// The JS endpoint is ready to handle any event.
// Register and post your events in this scope
bus.post("MyEvent", data: [1, 2, 3])

self.bus = bus // You can save your bus for firing events later
})

// Load web view content below
// ... Load web view content below
}
}
```
Expand All @@ -77,95 +84,17 @@ Caravel.getDefault().register("AnEvent", function(name, data) {

And voilà!

## API

### Swift - Caravel class

```swift
/**
* Returns the default bus
*/
static func getDefault(webView: UIWebView) -> Caravel
```

```swift
/**
* Returns custom bus
*/
static func get(name: String, webView: UIWebView) -> Caravel
```

```swift
/**
* Returns the current bus when its JS counterpart is ready
*/
func whenReady(callback: (Caravel) -> Void)
```

```swift
/**
* Posts event without any argument
*/
func post(eventName: String)
```

```swift
/**
* Posts event with extra data
*/
func post(eventName: String, anObject: AnyObject)
```

**NB:** Caravel is smart enough for serializing nested objects (eg. an array wrapped into a dictionary) when posting an event. However, this serialization only works if nested types are supported ones.

```swift
/**
* Subscribes to provided event. Callback is run with the event's name and extra data
*/
func register(eventName: String, callback: (String, AnyObject?) -> Void)
```

When receiving an event, you have to cast your data to the type you except. This cast is safe.

### JS - Caravel class

```js
/**
* Returns default bus
*/
static function getDefault()
```

```js
/**
* Returns custom bus
*/
static function get(name)
```

```js
/**
* Subscribes to provided event. Callback is called with event name first, then extra data if any
*/
static function register(name, callback)
```

```js
/**
* Posts event. Data are optional
*/
static function post(name, data)
```

## Troubleshooting

### I have my custom UIWebViewDelegate. What should I do?
### I want to use my custom UIWebViewDelegate. What should I do?

Caravel saves the current delegate, if any, before setting its own. So, if you would like to use your custom one, you have to set it before any call to Caravel.
To raise iOS events, Caravel must be the delegate of the provided `UIWebView`. However, if there is any existing delegate, Caravel saves it before setting its own. So, if you would like to use your custom one, simply set it before any call to Caravel.

### Reserved names

`CaravelInit` is an internal event, sent by the JS part for triggering the `whenReady` method.

Also, the default bus is named `default`. If you use that name for a custom bus, Caravel will automatically use the default one.
Also, the default bus is named `default`. If you use that name for a custom bus, Caravel will automatically switch to the default one.

### Keep in mind event and bus names are case-sensitive.

Loading

0 comments on commit c090de8

Please sign in to comment.