[swift-dev] Using Objective C class in Swift (open source, Linux)
Труб Илья
itrub at yandex.ru
Mon Feb 1 06:46:26 CST 2016
Everybody knows, that is very simple in XCode, there are many tutorials, for example,
http://stackoverflow.com/questions/24002369/how-to-call-objective-c-from-swift
or
https://github.com/gergelyorosz/swift-objective-c-mixed-project
But I read in some sources, that that is impossible in Linux (I have Ubuntu 15) for open source swift compiler. Is it true?
I mean, for example, such simple code:
file C.h
#import <Foundation/NSObject.h>
@interface C : NSObject
@property (copy) NSString *cu;
@end
file C.m
#import "C.h"
@implementation C
- (id)init { self = [super init]; self.cu = @"Hello world!"; return self; }
- (void)setCu:(NSString *)str { self.cu = str; }
@end
file s.swift
let c = C()
print(c.cu)
I can easily compile C.m in such way:
clang++ C.m -c -I<paths to headers on my host> -fblocks -o C.o
But how to import C.h to s.swift in order to avoid:
s.swift:2:9: error: use of unresolved identifier 'C'
let c = C()
We have not bridge-technology as in XCode.
In what way open source swift compiler could be developed to implement such feature?
More information about the swift-dev
mailing list