File tree Expand file tree Collapse file tree 4 files changed +14
-5
lines changed
Expand file tree Collapse file tree 4 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 1515#import < Foundation/Foundation.h>
1616
1717/* * A very contrived interface for writing strings to a file handle. */
18- @interface OIPrintStream : NSObject
18+ @interface OIPrintStream <PrintType> : NSObject
1919
2020- (nonnull instancetype )initWithFileHandle : (nonnull NSFileHandle *)fileHandle ;
2121
22+ - (void )print : (nonnull PrintType)message ;
23+
2224- (void )printString : (nonnull NSString *)message ;
2325
2426@end
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ - (instancetype)initWithFileHandle:(nonnull NSFileHandle *)fileHandle {
2525 return self;
2626}
2727
28+ - (void )print : (nonnull id )message {
29+ }
30+
2831- (void )printString : (nonnull NSString *)message {
2932 NSData *data = [message dataUsingEncoding: NSUTF8StringEncoding];
3033 [_fileHandle writeData: data];
Original file line number Diff line number Diff line change 1515import Foundation
1616import examples_apple_objc_interop_PrintStream
1717
18+ @objc public protocol MyStupid {
19+ }
20+
1821@objc ( OIPrinter)
1922public class Printer : NSObject {
2023
21- private let stream : OIPrintStream
24+ private let stream : OIPrintStream < MyStupid >
2225 private let prefix : String
2326
2427 @objc public init ( prefix: NSString ) {
2528 self . stream = OIPrintStream ( fileHandle: . standardOutput)
2629 self . prefix = prefix as String
2730 }
2831
32+ @objc public func stream( _ thing: MyStupid ) -> OIPrintStream < MyStupid > {
33+ return stream
34+ }
35+
2936 @objc public func print( _ message: NSString ) {
3037 stream. print ( " \( prefix) \( message) " )
3138 }
Original file line number Diff line number Diff line change 1414
1515#import < Foundation/Foundation.h>
1616
17- @protocol Stupid
18- @end
19-
2017/* * A very contrived interface for writing strings to a file handle. */
2118@interface OIPrintStream <PrintType> : NSObject
2219
You can’t perform that action at this time.
0 commit comments