Skip to content

Commit

Permalink
Merge pull request #20 from coshx/feat/add_bool_support
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
acadet committed Nov 11, 2015
2 parents 1fc5ae6 + 144c2ad commit c8efaeb
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 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.3"
version = "0.4.4"

s.name = "Caravel"
s.version = version
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- `NSArray`
- `NSDictionary`
* JavaScript ~> iOS supported types:
- `Bool`
- `Int`
- `Double`
- `String`
Expand Down
20 changes: 20 additions & 0 deletions caravel-test/EventDataController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ public class EventDataController: UIViewController {
bus.post("ComplexArray", anArray: [["name": "Alice", "age": 24], ["name": "Bob", "age": 23]])
bus.post("ComplexDictionary", aDictionary: ["name": "Cesar", "address": ["street": "Parrot", "city": "Perigueux"], "games": ["Fifa", "Star Wars"]])

bus.register("True") { name, data in
if let b = data as? Bool {
if b != true {
self._raise("True - bad value")
}
} else {
self._raise("True - bad type")
}
}

bus.register("False") { name, data in
if let b = data as? Bool {
if b != false {
self._raise("False - bad value")
}
} else {
self._raise("False - bad type")
}
}

bus.register("Int") { name, data in
if let i = data as? Int {
if i != 987 {
Expand Down
2 changes: 2 additions & 0 deletions caravel-test/js/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Caravel.getDefault().register("ComplexDictionary", function(name, data) {
}
});

Caravel.getDefault().post("True", true);
Caravel.getDefault().post("False", false);
Caravel.getDefault().post("Int", 987);
Caravel.getDefault().post("Float", 19.89);
Caravel.getDefault().post("Double", 15.15);
Expand Down
6 changes: 6 additions & 0 deletions caravel/DataSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ internal class DataSerializer {
return try! NSJSONSerialization.JSONObjectWithData(json, options: NSJSONReadingOptions())
}

if input == "true" {
return true
} else if input == "false" {
return false
}

var isNumber = true
for i in 0..<input.characters.count {
if Int(input[i]) != nil || input[i] == "." || input[i] == "," {
Expand Down
2 changes: 1 addition & 1 deletion caravel/js/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function (grunt) {
'use strict';

var version = '0.4.3';
var version = '0.4.4';

// Project configuration
grunt.initConfig({
Expand Down
2 changes: 1 addition & 1 deletion caravel/js/caravel.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c8efaeb

Please sign in to comment.