[swift-dev] Using Objective C class in Swift (open source, Linux)
Joe Groff
jgroff at apple.com
Mon Feb 1 10:44:00 CST 2016
> On Feb 1, 2016, at 4:46 AM, Труб Илья via swift-dev <swift-dev at swift.org> wrote:
>
>
>
> 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?
Swift only implements ObjC interop with Apple's ObjC runtime on iOS/tvOS/watchOS and 64-bit Mac. It could be ported to other runtimes in theory, but someone would have to do that work.
-Joe
More information about the swift-dev
mailing list