diff --git a/examples/apple/objc_interop/BUILD b/examples/apple/objc_interop/BUILD index f76bade28..53b20dbea 100644 --- a/examples/apple/objc_interop/BUILD +++ b/examples/apple/objc_interop/BUILD @@ -14,6 +14,7 @@ objc_library( name = "PrintStream", srcs = ["OIPrintStream.m"], hdrs = ["OIPrintStream.h"], + copts = ["-fmodules"], target_compatible_with = ["@platforms//os:macos"], ) @@ -22,12 +23,20 @@ swift_library( srcs = ["Printer.swift"], generated_header_name = "generated_header/Printer-Swift.h", generates_header = True, - deps = [":PrintStream"], + deps = [":PrintStream", ":Renderer"], +) + +swift_library( + name = "Renderer", + srcs = ["Renderer.swift"], + deps = [], + module_name = "Renderer", ) objc_library( name = "main", srcs = ["main.m"], + copts = ["-fmodules"], target_compatible_with = ["@platforms//os:macos"], deps = [":Printer"], ) diff --git a/examples/apple/objc_interop/Printer.swift b/examples/apple/objc_interop/Printer.swift index 3d65eb508..0f60f1636 100644 --- a/examples/apple/objc_interop/Printer.swift +++ b/examples/apple/objc_interop/Printer.swift @@ -14,19 +14,32 @@ import Foundation import examples_apple_objc_interop_PrintStream +import Renderer @objc(OIPrinter) public class Printer: NSObject { private let stream: OIPrintStream private let prefix: String + private let renderer: Renderer @objc public init(prefix: NSString) { self.stream = OIPrintStream(fileHandle: .standardOutput) self.prefix = prefix as String + self.renderer = Renderer(prefix:prefix) } @objc public func print(_ message: NSString) { stream.print("\(prefix)\(message)") } + + @objc public func print2(_ message: NSString, renderer: Renderer) { + stream.print("\(prefix)\(message)") + } } + +extension Printer: RenderProtocol { + public func render(_ name: String) { + stream.print(name) + } +} \ No newline at end of file diff --git a/examples/apple/objc_interop/Renderer.swift b/examples/apple/objc_interop/Renderer.swift new file mode 100644 index 000000000..d73e925bb --- /dev/null +++ b/examples/apple/objc_interop/Renderer.swift @@ -0,0 +1,36 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// 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. + +import Foundation + +@objc(SnapRenderer) +public class Renderer: NSObject { + + private let prefix: String + + @objc public init(prefix: NSString) { + self.prefix = prefix as String + } + + @objc public func printHaHa(_ message: NSString) { + print("\(prefix)\(message)") + } + +} + +@objc(SnapRenderProtocol) +public protocol RenderProtocol: NSObjectProtocol { + + func render(_ name: String) +} \ No newline at end of file