Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion examples/apple/objc_interop/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ objc_library(
name = "PrintStream",
srcs = ["OIPrintStream.m"],
hdrs = ["OIPrintStream.h"],
copts = ["-fmodules"],
target_compatible_with = ["@platforms//os:macos"],
)

Expand All @@ -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"],
)
Expand Down
13 changes: 13 additions & 0 deletions examples/apple/objc_interop/Printer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
36 changes: 36 additions & 0 deletions examples/apple/objc_interop/Renderer.swift
Original file line number Diff line number Diff line change
@@ -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)
}