From 8217477ff58f9210fc0e9dd6a78a825960e05d1a Mon Sep 17 00:00:00 2001 From: "Hyang-Ah (Hana) Kim" Date: Tue, 28 Jul 2015 19:19:41 -0400 Subject: [PATCH] example/bind: iOS Objective-C @ xcode example Change-Id: I10afa0961953e5a67f31479b564923b95ae5439f Reviewed-on: https://go-review.googlesource.com/12821 Reviewed-by: David Crawshaw --- example/bind/ios/README | 15 + .../bind/ios/bind.xcodeproj/project.pbxproj | 331 ++++++++++++++++++ example/bind/ios/bind/AppDelegate.h | 10 + example/bind/ios/bind/AppDelegate.m | 16 + .../bind/ios/bind/Base.lproj/LaunchScreen.xib | 41 +++ .../bind/ios/bind/Base.lproj/Main.storyboard | 50 +++ example/bind/ios/bind/Info.plist | 47 +++ example/bind/ios/bind/ViewController.h | 9 + example/bind/ios/bind/ViewController.m | 20 ++ example/bind/ios/bind/main.m | 12 + 10 files changed, 551 insertions(+) create mode 100644 example/bind/ios/README create mode 100644 example/bind/ios/bind.xcodeproj/project.pbxproj create mode 100644 example/bind/ios/bind/AppDelegate.h create mode 100644 example/bind/ios/bind/AppDelegate.m create mode 100644 example/bind/ios/bind/Base.lproj/LaunchScreen.xib create mode 100644 example/bind/ios/bind/Base.lproj/Main.storyboard create mode 100644 example/bind/ios/bind/Info.plist create mode 100644 example/bind/ios/bind/ViewController.h create mode 100644 example/bind/ios/bind/ViewController.m create mode 100644 example/bind/ios/bind/main.m diff --git a/example/bind/ios/README b/example/bind/ios/README new file mode 100644 index 0000000..d0203fd --- /dev/null +++ b/example/bind/ios/README @@ -0,0 +1,15 @@ +1. Use gomobile bind to bind the golang.org/x/mobile/example/bind/hello package. + The following command will create a static framework bundle in the current + directory. + + $ gomobile bind -target=ios golang.org/x/mobile/example/bind/hello + +2. Open the Xcode project by double clicking on bind.xcodeproj. + The project will not build - ViewController.m calls a function from the hello + package so requires the hello.framework the gomobild bind command created + in Step 1. + +3. Drag-and-drop the hello.framework from the desktop to the project navigation window. + This will automatically include the hello framework into the project. + +4. Build. diff --git a/example/bind/ios/bind.xcodeproj/project.pbxproj b/example/bind/ios/bind.xcodeproj/project.pbxproj new file mode 100644 index 0000000..a27e84b --- /dev/null +++ b/example/bind/ios/bind.xcodeproj/project.pbxproj @@ -0,0 +1,331 @@ +// !$*UTF8*$! + +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + EBA3E2861B681AFA00018449 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3E2851B681AFA00018449 /* main.m */; }; + EBA3E2891B681AFA00018449 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3E2881B681AFA00018449 /* AppDelegate.m */; }; + EBA3E28C1B681AFA00018449 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3E28B1B681AFA00018449 /* ViewController.m */; }; + EBA3E28F1B681AFA00018449 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EBA3E28D1B681AFA00018449 /* Main.storyboard */; }; + EBA3E2941B681AFA00018449 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = EBA3E2921B681AFA00018449 /* LaunchScreen.xib */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + EBA3E2801B681AFA00018449 /* bind.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = bind.app; sourceTree = BUILT_PRODUCTS_DIR; }; + EBA3E2841B681AFA00018449 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + EBA3E2851B681AFA00018449 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + EBA3E2871B681AFA00018449 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + EBA3E2881B681AFA00018449 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + EBA3E28A1B681AFA00018449 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + EBA3E28B1B681AFA00018449 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + EBA3E28E1B681AFA00018449 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + EBA3E2931B681AFA00018449 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + EBA3E27D1B681AFA00018449 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + EBA3E2771B681AFA00018449 = { + isa = PBXGroup; + children = ( + EBA3E2821B681AFA00018449 /* bind */, + EBA3E2811B681AFA00018449 /* Products */, + ); + sourceTree = ""; + }; + EBA3E2811B681AFA00018449 /* Products */ = { + isa = PBXGroup; + children = ( + EBA3E2801B681AFA00018449 /* bind.app */, + ); + name = Products; + sourceTree = ""; + }; + EBA3E2821B681AFA00018449 /* bind */ = { + isa = PBXGroup; + children = ( + EBA3E2871B681AFA00018449 /* AppDelegate.h */, + EBA3E2881B681AFA00018449 /* AppDelegate.m */, + EBA3E28A1B681AFA00018449 /* ViewController.h */, + EBA3E28B1B681AFA00018449 /* ViewController.m */, + EBA3E28D1B681AFA00018449 /* Main.storyboard */, + EBA3E2921B681AFA00018449 /* LaunchScreen.xib */, + EBA3E2831B681AFA00018449 /* Supporting Files */, + ); + path = bind; + sourceTree = ""; + }; + EBA3E2831B681AFA00018449 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + EBA3E2841B681AFA00018449 /* Info.plist */, + EBA3E2851B681AFA00018449 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + EBA3E27F1B681AFA00018449 /* bind */ = { + isa = PBXNativeTarget; + buildConfigurationList = EBA3E2A31B681AFB00018449 /* Build configuration list for PBXNativeTarget "bind" */; + buildPhases = ( + EBA3E2A91B68332F00018449 /* Run Script */, + EBA3E27C1B681AFA00018449 /* Sources */, + EBA3E27D1B681AFA00018449 /* Frameworks */, + EBA3E27E1B681AFA00018449 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = bind; + productName = bind; + productReference = EBA3E2801B681AFA00018449 /* bind.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + EBA3E2781B681AFA00018449 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0630; + ORGANIZATIONNAME = "Hana (Hyang-Ah) Kim"; + TargetAttributes = { + EBA3E27F1B681AFA00018449 = { + CreatedOnToolsVersion = 6.3.2; + }; + }; + }; + buildConfigurationList = EBA3E27B1B681AFA00018449 /* Build configuration list for PBXProject "bind" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = EBA3E2771B681AFA00018449; + productRefGroup = EBA3E2811B681AFA00018449 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + EBA3E27F1B681AFA00018449 /* bind */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + EBA3E27E1B681AFA00018449 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EBA3E28F1B681AFA00018449 /* Main.storyboard in Resources */, + EBA3E2941B681AFA00018449 /* LaunchScreen.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + EBA3E2A91B68332F00018449 /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "${SRCROOT}/genhello.bash"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + EBA3E27C1B681AFA00018449 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EBA3E28C1B681AFA00018449 /* ViewController.m in Sources */, + EBA3E2891B681AFA00018449 /* AppDelegate.m in Sources */, + EBA3E2861B681AFA00018449 /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + EBA3E28D1B681AFA00018449 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + EBA3E28E1B681AFA00018449 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + EBA3E2921B681AFA00018449 /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + EBA3E2931B681AFA00018449 /* Base */, + ); + name = LaunchScreen.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + EBA3E2A11B681AFB00018449 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + EBA3E2A21B681AFB00018449 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + EBA3E2A41B681AFB00018449 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + ); + INFOPLIST_FILE = bind/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + EBA3E2A51B681AFB00018449 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + ); + INFOPLIST_FILE = bind/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + EBA3E27B1B681AFA00018449 /* Build configuration list for PBXProject "bind" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EBA3E2A11B681AFB00018449 /* Debug */, + EBA3E2A21B681AFB00018449 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + EBA3E2A31B681AFB00018449 /* Build configuration list for PBXNativeTarget "bind" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EBA3E2A41B681AFB00018449 /* Debug */, + EBA3E2A51B681AFB00018449 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = EBA3E2781B681AFA00018449 /* Project object */; +} diff --git a/example/bind/ios/bind/AppDelegate.h b/example/bind/ios/bind/AppDelegate.h new file mode 100644 index 0000000..642915d --- /dev/null +++ b/example/bind/ios/bind/AppDelegate.h @@ -0,0 +1,10 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#import + +@interface AppDelegate : UIResponder +@property (strong, nonatomic) UIWindow *window; +@end + diff --git a/example/bind/ios/bind/AppDelegate.m b/example/bind/ios/bind/AppDelegate.m new file mode 100644 index 0000000..e10ee2d --- /dev/null +++ b/example/bind/ios/bind/AppDelegate.m @@ -0,0 +1,16 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#import "AppDelegate.h" + +@interface AppDelegate () +@end + +@implementation AppDelegate + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + return YES; +} + +@end diff --git a/example/bind/ios/bind/Base.lproj/LaunchScreen.xib b/example/bind/ios/bind/Base.lproj/LaunchScreen.xib new file mode 100644 index 0000000..6ed6eb6 --- /dev/null +++ b/example/bind/ios/bind/Base.lproj/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/bind/ios/bind/Base.lproj/Main.storyboard b/example/bind/ios/bind/Base.lproj/Main.storyboard new file mode 100644 index 0000000..9b035c5 --- /dev/null +++ b/example/bind/ios/bind/Base.lproj/Main.storyboard @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/bind/ios/bind/Info.plist b/example/bind/ios/bind/Info.plist new file mode 100644 index 0000000..fa5adf4 --- /dev/null +++ b/example/bind/ios/bind/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + org.golang.example.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/example/bind/ios/bind/ViewController.h b/example/bind/ios/bind/ViewController.h new file mode 100644 index 0000000..4b38773 --- /dev/null +++ b/example/bind/ios/bind/ViewController.h @@ -0,0 +1,9 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#import + +@interface ViewController : UIViewController +@property (strong, nonatomic) IBOutlet UILabel *textLabel; +@end diff --git a/example/bind/ios/bind/ViewController.m b/example/bind/ios/bind/ViewController.m new file mode 100644 index 0000000..0ef836b --- /dev/null +++ b/example/bind/ios/bind/ViewController.m @@ -0,0 +1,20 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#import "ViewController.h" +#import "hello/Hello.h" // Gomobile bind generated header file in hello.framework + +@interface ViewController () +@end + +@implementation ViewController + +@synthesize textLabel; + +- (void)loadView { + [super loadView]; + textLabel.text = GoHelloGreetings(@"iOS and Gopher"); +} + +@end diff --git a/example/bind/ios/bind/main.m b/example/bind/ios/bind/main.m new file mode 100644 index 0000000..c9dcc2d --- /dev/null +++ b/example/bind/ios/bind/main.m @@ -0,0 +1,12 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +}