Commit 69ebe88c authored by Andrew Twyman's avatar Andrew Twyman Committed by GitHub

Merge pull request #301 from 4brunu/ObjcSwiftBridgingHEader

Generate bridging header for Swift
parents 0c1aa241 66f6d9b4
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni
#import "TXSItemList.h"
#import "TXSSortOrder.h"
#import "TXSSortItems.h"
#import "TXSTextboxListener.h"
#import "TXSItemList.h"
#import "TXSSortItems.h"
#import "TextSort-Swift.h"
#import "TXSTextboxListenerImpl.h"
#import "TXSViewController.h"
#import "TXSTextboxListener.h"
......@@ -12,6 +13,8 @@
@property (nonatomic) IBOutlet UIButton *button;
@property (nonatomic) IBOutlet UISwitch *switchDebugMode;
@end
@implementation TXSViewController {
......@@ -33,11 +36,28 @@
action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
// Create the Objective-C TXSTextboxListener
_textboxListener = [[TXSTextboxListenerImpl alloc] initWithUITextView:self.textView];
[self createSorter];
}
-(void)createSorter
{
if (_switchDebugMode.isOn) {
// Create the Swift TXSTextboxListener
_textboxListener = [[TXSTextboxListenerDebugableImpl alloc] initWithUITextView:self.textView];
}
else {
// Create the Objective-C TXSTextboxListener
_textboxListener = [[TXSTextboxListenerImpl alloc] initWithUITextView:self.textView];
}
_sortItemInterface = [TXSSortItems createWithListener:_textboxListener];
}
-(IBAction)toggleDebugMode:(id)sender
{
[self createSorter];
}
- (IBAction)sort:(id)sender
{
[self sortWithOrder:TXSSortOrderAscending];
......
import UIKit
final class TXSTextboxListenerDebugableImpl : NSObject, TXSTextboxListener {
private var textView: UITextView
@available(*, unavailable)
override init() {
fatalError("Unsupported")
}
@objc(initWithUITextView:)
init(textView: UITextView) {
self.textView = textView
}
func update(_ items: TXSItemList) {
let string = items.items.joined(separator: "\n")
print("TXSTextboxListenerDebugableImpl -> update \n\(string)")
textView.text = string
}
}
......@@ -17,6 +17,7 @@
65D7FDFB19AD0CDF0038F82F /* TXSAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 65D7FDF519AD0CDF0038F82F /* TXSAppDelegate.m */; };
65D7FDFC19AD0CDF0038F82F /* TXSTextboxListenerImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = 65D7FDF719AD0CDF0038F82F /* TXSTextboxListenerImpl.m */; };
65D7FDFD19AD0CDF0038F82F /* TXSViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 65D7FDF919AD0CDF0038F82F /* TXSViewController.m */; };
A546A26E1E72FBAF004A8BBD /* TXSTextboxListenerDebugableImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = A546A26D1E72FBAF004A8BBD /* TXSTextboxListenerDebugableImpl.swift */; };
B003051919B70561008E1F67 /* libdjinni_objc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B003051819B70561008E1F67 /* libdjinni_objc.a */; };
B097B6BC19B1C07E0047653A /* libtextsort_objc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B097B6BB19B1C07E0047653A /* libtextsort_objc.a */; };
/* End PBXBuildFile section */
......@@ -38,6 +39,7 @@
65D7FDF719AD0CDF0038F82F /* TXSTextboxListenerImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TXSTextboxListenerImpl.m; sourceTree = "<group>"; };
65D7FDF819AD0CDF0038F82F /* TXSViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TXSViewController.h; sourceTree = "<group>"; };
65D7FDF919AD0CDF0038F82F /* TXSViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TXSViewController.m; sourceTree = "<group>"; };
A546A26D1E72FBAF004A8BBD /* TXSTextboxListenerDebugableImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TXSTextboxListenerDebugableImpl.swift; path = "../handwritten-src/swift/TXSTextboxListenerDebugableImpl.swift"; sourceTree = "<group>"; };
B003051819B70561008E1F67 /* libdjinni_objc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libdjinni_objc.a; path = "../../support-lib/build/Debug-iphoneos/libdjinni_objc.a"; sourceTree = "<group>"; };
B097B6BB19B1C07E0047653A /* libtextsort_objc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtextsort_objc.a; path = "../../build/Debug-iphoneos/libtextsort_objc.a"; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -61,6 +63,7 @@
65834DD419AC599E0061AD3F = {
isa = PBXGroup;
children = (
A546A26A1E72F967004A8BBD /* handwritten-swift */,
65D7FDF219AD0C730038F82F /* handwritten-objc */,
65834DE619AC599E0061AD3F /* TextSort */,
65834DDF19AC599E0061AD3F /* Frameworks */,
......@@ -123,6 +126,14 @@
path = "../handwritten-src/objc";
sourceTree = "<group>";
};
A546A26A1E72F967004A8BBD /* handwritten-swift */ = {
isa = PBXGroup;
children = (
A546A26D1E72FBAF004A8BBD /* TXSTextboxListenerDebugableImpl.swift */,
);
name = "handwritten-swift";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
......@@ -152,6 +163,11 @@
CLASSPREFIX = TXS;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = "Dropbox, Inc.";
TargetAttributes = {
65834DDC19AC599E0061AD3F = {
LastSwiftMigration = 0820;
};
};
};
buildConfigurationList = 65834DD819AC599E0061AD3F /* Build configuration list for PBXProject "TextSort" */;
compatibilityVersion = "Xcode 3.2";
......@@ -192,6 +208,7 @@
65D7FDFC19AD0CDF0038F82F /* TXSTextboxListenerImpl.m in Sources */,
65D7FDFB19AD0CDF0038F82F /* TXSAppDelegate.m in Sources */,
65D7FDFD19AD0CDF0038F82F /* TXSViewController.m in Sources */,
A546A26E1E72FBAF004A8BBD /* TXSTextboxListenerDebugableImpl.swift in Sources */,
65D7FDFA19AD0CDF0038F82F /* main.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -308,12 +325,17 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CLANG_ENABLE_MODULES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "TextSort/TextSort-Prefix.pch";
INFOPLIST_FILE = "TextSort/TextSort-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = "Dropbox.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "../generated-src/objc/TextSort-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
};
......@@ -324,12 +346,16 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CLANG_ENABLE_MODULES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "TextSort/TextSort-Prefix.pch";
INFOPLIST_FILE = "TextSort/TextSort-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = "Dropbox.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "../generated-src/objc/TextSort-Bridging-Header.h";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
};
......
......@@ -66,9 +66,10 @@ fi
--ident-jni-class NativeFooBar \
--ident-jni-file NativeFooBar \
\
--objc-out "$temp_out/objc" \
--objcpp-out "$temp_out/objc" \
--objc-out "$temp_out/objc" \
--objcpp-out "$temp_out/objc" \
--objc-type-prefix TXS \
--objc-swift-bridging-header "TextSort-Bridging-Header" \
\
--idl "$in"
......
......@@ -8,10 +8,10 @@
</extension>
<option name="MAIN_CLASS_NAME" value="djinni.Main" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="--java-out djinni-output-temp/java --java-package com.dropbox.textsort --ident-java-field mFooBar --cpp-out djinni-output-temp/cpp --cpp-namespace textsort --ident-cpp-enum-type foo_bar --jni-out djinni-output-temp/jni --ident-jni-class NativeFooBar --ident-jni-file NativeFooBar --objc-out djinni-output-temp/objc --objcpp-out djinni-output-temp/objc --objc-type-prefix TXS --idl example.djinni" />
<option name="PROGRAM_PARAMETERS" value="--java-out djinni-output-temp/java --java-package com.dropbox.textsort --ident-java-field mFooBar --cpp-out djinni-output-temp/cpp --cpp-namespace textsort --ident-cpp-enum-type foo_bar --jni-out djinni-output-temp/jni --ident-jni-class NativeFooBar --ident-jni-file NativeFooBar --objc-out djinni-output-temp/objc --objcpp-out djinni-output-temp/objc --objc-type-prefix TXS --objc-swift-bridging-header TextSort-Bridging-Header --idl example.djinni" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/../example" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" value="" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
......
......@@ -68,6 +68,7 @@ object Main {
var objcTypePrefix: String = ""
var objcIncludePrefix: String = ""
var objcExtendedRecordIncludePrefix: String = ""
var objcSwiftBridgingHeader: Option[String] = None
var objcppIncludePrefix: String = ""
var objcppIncludeCppPrefix: String = ""
var objcppIncludeObjcPrefixOptional: Option[String] = None
......@@ -164,6 +165,8 @@ object Main {
.text("The prefix for Objective-C data types (usually two or three letters)")
opt[String]("objc-include-prefix").valueName("<prefix>").foreach(objcIncludePrefix = _)
.text("The prefix for #import of header files from Objective-C files.")
opt[String]("objc-swift-bridging-header").valueName("<name>").foreach(x => objcSwiftBridgingHeader = Some(x))
.text("The name of Objective-C Bridging Header used in XCode's Swift projects.")
note("")
opt[File]("objcpp-out").valueName("<out-folder>").foreach(x => objcppOutFolder = Some(x))
.text("The output folder for private Objective-C++ files (Generator disabled if unspecified).")
......@@ -282,6 +285,14 @@ object Main {
} else {
None
}
val objcSwiftBridgingHeaderWriter = if (objcSwiftBridgingHeader.isDefined && objcOutFolder.isDefined) {
val objcSwiftBridgingHeaderFile = new File(objcOutFolder.get.getPath, objcSwiftBridgingHeader.get + ".h")
if (objcSwiftBridgingHeaderFile.getParentFile != null)
createFolder("output file list", objcSwiftBridgingHeaderFile.getParentFile)
Some(new BufferedWriter(new FileWriter(objcSwiftBridgingHeaderFile)))
} else {
None
}
val outSpec = Spec(
javaOutFolder,
......@@ -330,6 +341,7 @@ object Main {
objcppIncludeObjcPrefix,
objcppNamespace,
objcBaseLibIncludePrefix,
objcSwiftBridgingHeaderWriter,
outFileListWriter,
skipGeneration,
yamlOutFolder,
......@@ -345,6 +357,9 @@ object Main {
if (outFileListWriter.isDefined) {
outFileListWriter.get.close()
}
if (objcSwiftBridgingHeaderWriter.isDefined) {
objcSwiftBridgingHeaderWriter.get.close()
}
}
}
}
/**
* Copyright 2016 Dropbox, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package djinni
import java.io._
import djinni.ast._
import djinni.generatorTools._
class SwiftBridgingHeaderGenerator(spec: Spec) extends Generator(spec) {
val marshal = new ObjcMarshal(spec)
override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum) {
spec.objcSwiftBridgingHeaderWriter.get.write("#import \"" + marshal.headerName(ident) + "\"\n")
}
override def generateInterface(origin: String, ident: Ident, doc: Doc, typeParams: Seq[TypeParam], i: Interface) {
spec.objcSwiftBridgingHeaderWriter.get.write("#import \"" + marshal.headerName(ident) + "\"\n")
}
override def generateRecord(origin: String, ident: Ident, doc: Doc, params: Seq[TypeParam], r: Record) {
spec.objcSwiftBridgingHeaderWriter.get.write("#import \"" + marshal.headerName(ident) + "\"\n")
}
}
object SwiftBridgingHeaderGenerator {
def writeAutogenerationWarning(writer: Writer) {
writer.write("// AUTOGENERATED FILE - DO NOT MODIFY!\n")
writer.write("// This file generated by Djinni\n\n")
}
}
\ No newline at end of file
......@@ -74,6 +74,7 @@ package object generatorTools {
objcppIncludeObjcPrefix: String,
objcppNamespace: String,
objcBaseLibIncludePrefix: String,
objcSwiftBridgingHeaderWriter: Option[Writer],
outFileListWriter: Option[Writer],
skipGeneration: Boolean,
yamlOutFolder: Option[File],
......@@ -213,6 +214,10 @@ package object generatorTools {
}
new ObjcppGenerator(spec).generate(idl)
}
if (spec.objcSwiftBridgingHeaderWriter.isDefined) {
SwiftBridgingHeaderGenerator.writeAutogenerationWarning(spec.objcSwiftBridgingHeaderWriter.get)
new SwiftBridgingHeaderGenerator(spec).generate(idl)
}
if (spec.yamlOutFolder.isDefined) {
if (!spec.skipGeneration) {
createFolder("YAML", spec.yamlOutFolder.get)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment