This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class Debug { | |
static var window: UIWindow? | |
static func setupWindowIfNeeded() { | |
guard Debug.window == nil else { return } | |
guard Environment.current != .release else { return } | |
let window = UIWindow(frame: UIScreen.main.bounds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MyPrivateClass.h | |
@interface MyPrivateClass: NSObject | |
- (void) doSomethingInternalWithSecretAttribute:(NSInteger)attribute; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Somewhere in the wild west | |
import MyFramework | |
... | |
// This should work | |
let publicClass = MyPublicClass() | |
publicClass.doSomethingWithPrivateClass() | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MyPublicClass.swift | |
import MyFramework.Private // Required to see "private" header | |
public class MyPublicClass { | |
private let privateClass: MyPrivateClass | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Somewhere in the wild west | |
import MyFramework | |
import MyFramework.Private | |
... | |
// This should not be possible, nor even compile, | |
// as it should not be able to see MyPrivateClass | |
let privateClass = MyPrivateClass() | |
privateClass.doSomethingInternal(withSecretAttribute: 13) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ObjectiveCToSwift.swift | |
@objc(MyPrivateClassProtocol) // Under this name this will cross Swift->ObjC boundary | |
internal protocol MyPrivateClass { | |
init() | |
func doSomethingInternal(withSecretAttribute: Int) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SwiftToObjectiveC.h | |
#ifndef SwiftToObjectiveC_h | |
#define SwiftToObjectiveC_h | |
SWIFT_PROTOCOL_NAMED("MyPrivateClassProtocol") | |
@protocol MyPrivateClassProtocol | |
- (nonnull instancetype)init; | |
- (void)doSomethingInternalWithSecretAttribute:(NSInteger)attribute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MyPrivateClass.h | |
#import <Foundation/Foundation.h> | |
#import <SwiftToObjectiveC.h> | |
@interface MyPrivateClass : NSObject<MyPrivateClassProtocol> | |
- (void) doSomethingInternalWithSecretAttribute:(NSInteger)attribute; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol SomeProtocol { | |
init() | |
} | |
class SomeClass: SomeProtocol { | |
... | |
} | |
// This will work | |
let instance: SomeProtocol = SomeClass.init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
@objc(Factory) | |
internal class Factory: NSObject { | |
private static var privateClassType: MyPrivateClass.Type! | |
@objc static func registerPrivateClassType(type: MyPrivateClass.Type) { | |
print("REGISTRATION CALLED WITH TYPE = \(type)") | |
privateClassType = type | |
} |
OlderNewer