Skip to content

Latest commit

 

History

History
89 lines (52 loc) · 2.06 KB

SettingUpANewProject.md

File metadata and controls

89 lines (52 loc) · 2.06 KB

Setting up a new project

To set up a brand new Xcode project using UIKit on the Apple Watch:

  1. Create a new iOS App with WatchKit App project:

New Project Type

New Project Options

New Project Location

  1. Add a Watch Framework target:

New Framework Type

New Framework Options

  1. Add main.m, AppDelegate.h, and AppDelegate.m to the new target:

New File...

main.m:

New File Type

New Objective-C File Options

New Objective-C File Location

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

void __attribute__((constructor)) injected_main()
{
    @autoreleasepool {
        UIApplicationMain(0, nil, @"UIApplication", NSStringFromClass([AppDelegate class]));
    }
}

AppDelegate.h:

New File Type

New Header File Location

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

AppDelegate.m:

New File Type

New Objective-C File Options

New Objective-C File Location

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Initialize `self.window`. See AppleWatchUIKitFramework/AppDelegate.m for an example
    return YES;
}

@end
  1. Patch WatchOS frameworks as described in Running this example.

  2. Create a build script to patch the WatchKit app so it loads the framework target's executable. See AppleWatchUIKit/build.sh for an example.