I have a mixed-language project, Objective C and Swift, in XCode 6.
Singleton.h
#import <Foundation/Foundation.h>
enum {
enum_A = 0,
enum_B,
enum_C,
enum_D,
enum_E,
enum_F,
enum_G,
} enums;
@interface Singleton : NSObject
+ (id)sharedSingleton;
@end
Singleton.m
// Nothing's special in this file
#import "Singleton.h"
static Singleton *shared = nil;
@implementation Singleton
- (id)init {
self = [super init];
if (self) {
}
return self;
}
#pragma mark - Interface
+ (Singleton *)sharedSingleton {
static dispatch_once_t pred;
dispatch_once(&pred, ^{
shared = [[Singleton alloc] init];
});
return shared;
}
@end
ViewController.swift
import UIKit
class ViewController: UIViewController {
let singleton = Singleton.sharedSingleton() as Singleton
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let n = NSNumber(char: enum_E) // ERROR HERE!!!
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
(Of course I had to setup bridging header file, having #import "Singleton.h"
added).
The ERROR is:
Cannot invoke 'init' with an argument list of type '(char: Int)'
It's strange that Swift can still recognize enum_E
(I see it colorized in blue) but still pops up this error.
I tried (char)enum_E
but still no luck.
Do you have any ideas?
Thanks,
NSNumber(int: enum_E)
?