I have come across an issue with the console in my project in Xcode. I am able to debug a Swift Singleton inside Swift but not Objective-C, in Xcode 8 and 9, Swift 3 and 4.
The question is, why can't the values in question be printed in the console when debugging an Objective-C class? There is no issue when debugging in a Swift class, and the console even auto completes the swift class for me.
Example classes:
Objective-C View Controller
#import "ViewController.h"
#import "SOQuestion-Swift.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"Property: %@", SOSingleton.instance.appleProperty);
NSLog(@"Return: %@", [[SOSingleton instance] apple]);
SOSingleton *so = [SOSingleton instance];
NSLog(@"Object: %@", so);
}
Swift Class
import Foundation
@objcMembers
public class SOSingleton: NSObject {
public static let instance = SOSingleton()
public override init() {
super.init()
}
public func apple() -> String {
return "apple"
}
public let appleProperty = "apple"
}
Generated Header for Swift class
SWIFT_CLASS("_TtC10SOQuestion11SOSingleton")
@interface SOSingleton : NSObject
SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, strong) SOSingleton * _Nonnull instance;)
+ (SOSingleton * _Nonnull)instance SWIFT_WARN_UNUSED_RESULT;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
- (NSString * _Nonnull)apple SWIFT_WARN_UNUSED_RESULT;
@property (nonatomic, readonly, copy) NSString * _Nonnull appleProperty;
@end
The output of the logs is as follows :
Property: apple
Return: apple
Object: <SOQuestion.SOSingleton: 0x60800003e140>
The output of logging is as follows (while debugging the ViewController) :
(lldb) po [[SOSingleton instance] apple]
Error [IRForTarget]: Couldn't resolve the class for an Objective-C
static method call
error: The expression could not be prepared to run in the target