Skip to content

Commit 587a297

Browse files
Better readme
1 parent e2f9cb2 commit 587a297

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

README.markdown

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
# Overview
22

3+
GAJavaScript is a Cocoa Touch library that makes working with JavaScript easier from native code. It has a couple of important design goals:
4+
5+
1. Make working with JavaScript objects and functions more like working with Objective-C objects and methods.
6+
2. Allow native applications on iOS devices to take advantage of JavaScript to support sharing code across platforms or making applications more dynamic.
7+
3. Don't get in the way of developers!
8+
9+
# Classes
10+
11+
JavaScript is accessed from Cocoa Touch using UIWebView. To that end, the main entry point of this library is a category on UIWebView.
12+
13+
## UIWebView+GAJavaScript
14+
15+
This category adds accessors to access the "document" and "window" objects of the HTML document loaded in the webview.
16+
17+
## GAScriptObject
18+
19+
This object provides a wrapper around a JavaScript object in a UIWebView. It provides a KVC view for a JavaScript object, so that you can get and set the object's properties using valueForKey: and setValue:forKey:, as you would with other Objective-C classes.
20+
21+
GAScriptObject handles marshaling of data between the languages. It will handle quoting strings, passing dates as "time_t" values, and dealing with sub-objects and arrays.
22+
23+
# Using it
24+
25+
There are unit tests in the /Tests folder that show how to use various features (and they make sure the features work!).

Tests/TScriptObject.m

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ - (void)testKeyValueCoding
7171
- (void)finishKeyValueCoding
7272
{
7373
NSArray* kTestValues = [NSArray arrayWithObjects:
74-
@"abcd",
75-
@"string 'with' quotes",
76-
[NSNumber numberWithInt:400000],
77-
[NSNumber numberWithFloat:0.55555],
78-
[NSNull null],
79-
[NSNumber numberWithBool:YES],
80-
[NSDate date],
74+
@"abcd", // String
75+
@"string 'with' quotes", // String that needs escaping
76+
[NSNumber numberWithInt:400000], // Number (Integer)
77+
[NSNumber numberWithFloat:0.55555], // Number (Float)
78+
[NSNull null], // Null
79+
[NSNumber numberWithBool:YES], // Boolean
80+
[NSDate date], // Date
8181
nil];
8282

8383
NSInteger status = kGHUnitWaitStatusSuccess;
@@ -100,6 +100,8 @@ - (void)finishKeyValueCoding
100100
}
101101
else if ([testValue isKindOfClass:[NSDate class]])
102102
{
103+
// There will be a sub-second difference between the values due to rounding of NSTimeInterval
104+
// when it's passed into JavaScript. So we validate that the times are within 1 second.
103105
if ([testValue timeIntervalSinceDate:gotValue] >= 1.0)
104106
status = kGHUnitWaitStatusFailure;
105107
}

0 commit comments

Comments
 (0)