Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hikui committed Jul 21, 2014
1 parent 1390de9 commit 8832549
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions EMControllerManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
7F4DE975197375160030B821 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7F4DE973197375160030B821 /* InfoPlist.strings */; };
7F4DE97E197375840030B821 /* EMControllerManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 7F4DE97C197375840030B821 /* EMControllerManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
7F4DE97F197375840030B821 /* EMControllerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F4DE97D197375840030B821 /* EMControllerManager.m */; };
7FAF60F6197CA43F00D9BE2F /* ViewControllerConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7FAF60F5197CA43F00D9BE2F /* ViewControllerConfig.plist */; };
7FF4978F1973B7C200512033 /* ViewControllerConfig.json in Resources */ = {isa = PBXBuildFile; fileRef = 7FF4978E1973B7C200512033 /* ViewControllerConfig.json */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -71,6 +72,7 @@
7F4DE976197375160030B821 /* EMControllerManager-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "EMControllerManager-Prefix.pch"; sourceTree = "<group>"; };
7F4DE97C197375840030B821 /* EMControllerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EMControllerManager.h; sourceTree = "<group>"; };
7F4DE97D197375840030B821 /* EMControllerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EMControllerManager.m; sourceTree = "<group>"; };
7FAF60F5197CA43F00D9BE2F /* ViewControllerConfig.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ViewControllerConfig.plist; sourceTree = "<group>"; };
7FF4978E1973B7C200512033 /* ViewControllerConfig.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ViewControllerConfig.json; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -132,6 +134,7 @@
7F4C2DB51973A3DB006045F8 /* Test4ViewController.h */,
7F4C2DB61973A3DB006045F8 /* Test4ViewController.m */,
7FF4978E1973B7C200512033 /* ViewControllerConfig.json */,
7FAF60F5197CA43F00D9BE2F /* ViewControllerConfig.plist */,
);
path = EMControllerManagerExample;
sourceTree = "<group>";
Expand Down Expand Up @@ -315,6 +318,7 @@
buildActionMask = 2147483647;
files = (
7F4C2D8519739E12006045F8 /* InfoPlist.strings in Resources */,
7FAF60F6197CA43F00D9BE2F /* ViewControllerConfig.plist in Resources */,
7FF4978F1973B7C200512033 /* ViewControllerConfig.json in Resources */,
7F4C2D8D19739E12006045F8 /* Images.xcassets in Resources */,
);
Expand Down
20 changes: 20 additions & 0 deletions EMControllerManagerExample/ViewControllerConfig.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Test1</key>
<dict>
<key>ClassName</key>
<string>Test1ViewController</string>
<key>Description</key>
<string>Test1 description</string>
<key>Tag</key>
<integer>100</integer>
<key>Dependencies</key>
<dict>
<key>dependentString</key>
<string>depstr</string>
</dict>
</dict>
</dict>
</plist>
10 changes: 7 additions & 3 deletions EMControllerManagerHeaderGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import getopt
import json
import sys
import plistlib

def generate_definition(input_file, output_path, prefix):

with open(input_file, 'r') as json_file:
json_string = json_file.read()
config_dict = json.loads(json_string)
with open(input_file, 'r') as f:
raw_string = f.read()
try:
config_dict = json.loads(raw_string)
except Exception, e:
config_dict = plistlib.readPlistFromString(raw_string)
if not isinstance(config_dict,dict):
sys.stderr.write('configuration file is not failed')
exit(-1)
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,12 @@ In your view controller:
UIViewController *vc = [cm createViewControllerInstanceNamed:@"Test1" withPropertyValues:@{@"color":[UIColor redColor],@"number":@(1)}];

`createViewControllerInstanceNamed:withPropertyValues:` will create an instance of a configured class. You can pass a dictionary through `PropertyValues`. How these values are handled depends on the instance. If it conforms the `EMControllerManagerInitProtocol` and responds to `initializePropertiesWithDictionary:`, then this method will be called. Otherwise, the values in the dictionary will be injected into the instance directly by KVC.

## Autocompelete?

I hate configuration files because it won't trigger the autocompelete tool. Appearently, it's a drawback. But we still have some workarounds. The way I deal with the problem is by using a python script to generate a header file, where all controller names are defined in macros, thus we can trigger the autocomplete. There is a python script named `EMControllerManagerHeaderGenerator.py` in this repository. You can generate the header file by a command like:

python EMControllerManagerHeaderGenerator.py -i your_config_file -o header_file_path -p prefix



0 comments on commit 8832549

Please sign in to comment.