Developer of ParseKit here.
OK, after working through a tricky issue in Xcode 4, I have figured out my preferred way to do this: Create a new Workspace ("MySuite") which contains two sub-Projects
- Your Mac Cocoa Application Project ("MyApp")
- The ParseKit Framework Project ("ParseKit")
You can choose different names than "MyApp" and "MySuite" of course.
There's a few different ways to make this happen. Here's one way:
First, make sure you update to the very latest version of the ParseKit from the Google Code trunk. I have recently modernized the Xcode project for Xcode 4.3.1.
svn checkout http://parsekit.googlecode.com/svn/trunk/ parsekit-trunk
Make sure you do not have the ParseKit Xcode Project window open. This is an issue in Xcode up to version 4.3.1 (and maybe later, not sure).
- Create a Mac "Cocoa Application" Project named "MyApp".
File > New > Project…
. (You may have already created your app. That's fine. Then skip this step.)
- Drag the
ParseKit.xcodeproj
file from the Finder to the very top of the Project Navigator in the "MyApp" Xcode Project window. NOTE: make sure you drop the file at the very top of the Project Navigator tree. Otherwise it will not work.
- Xcode will present a dialog: "Do you want to save this project in a new workspace?" Click "Save" and name the Workspace something like "MySuite".
- Select the "MyApp" Project in the Project Navigtor.
- Select the "MyApp" Target in the "Targets" list.
- Select the "Build Phases" tab.
- Click the disclosure triangle next to "Target Dependencies" to open the list.
- Click the "+" button at the bottom of the list.
- Select "ParseKit.framework" from the resulting dialog and click "Add" to add ParseKit as a dependency of your target. This ensures ParseKit is built before your target.
- Click the disclosure triangle next to "Link Binary With Libraries" to open the list.
- Click the "+" button at the bottom of the list.
- Select "ParseKit.framework" from the resulting dialog and click "Add".
- Click the disclosure triangle next to "Link Binary With Libraries" to open the list.
- Click the "+" button at the bottom of the list.
- Select "ParseKit.framework" from the resulting dialog and click "Add".
- See "ParseKit.framework" in the "Link Binary With Libraries" list.
- Click the "Add Build Phase" Button, choose "Copy Files" in the popup.
- In the new "Copy Files" build phase, select "Frameworks" in the "Destination" popup.
- Drag "ParseKit.framework" from the Project Navigator to the list in the new "Copy Files" build phase.
In MyAppDelegate.m
, import the ParseKit header:
#import <ParseKit/ParseKit.h>
In -[MyAppDelegate applicationDidFinishLaunching:]
do:
NSString *g = @"@start = Word+;";
PKParser *p = [[PKParserFactory factory] parserFromGrammar:g assembler:self error:nil];
NSError *err = nil;
id result = [p parse:@"foo bar baz" error:&err];
NSLog(@"%@", result);
- Build and run.
For more info on this topic, see:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…