Objective-C and Swift ABI - objective-c

I know there are still some ABI (Application Binary Interface) issues between different versions of Swift, and it can cause a framework built with one version of Swift to not usable by an application built with another version of Swift.
But I am not sure if Objective-C and Swift have such an issue. That is to say, can a framework built with Swift be consumed by any version of Objective-C, in the ABI context?

Related

is static library with Objective C compatible with any version of XCode?

I am from c++ background and in c++ world, if I create an static library with any specific version of a compiler, then it is advisable to use same version of compiler for binary which will use this static library.
Is this statement true for Objective C static library as well? or if I have Objective C static library compiled with XCode X & and executable compiled with XCode Y still there will be no conflict?
Yes no conflicts. Migration of my legacy project on Objective-C to Xcode 12 was done without problems: just opened and compiled. Despite my colleagues: they had to continue working with Xcode 10 and 11 on swift projects.
Objective-C is ABI, Module and Source stable language like C, despite C++ and Swift

Cant import AppKit in ObjC-module of SwiftPM

I tried to import AppKit in a Header of an Module of a Swift-Packet with this code:
#import <AppKit/AppKit.h>
But the compiler threw this error:
fatal error: 'AppKit/AppKit.h' file not found
Should I specify it somehow as dependency in the Package.swift file of the Package?
Thanks in advance
Michael
Note that Swift Package Manager (SPM) is intended for the Server Side Swift, not for the Client Side. Concretely, AppKit was probably not ported to the Server Side Swift, so you could not be able to use AppKit with SPM. AppKit is part of the Objective-C runtime. SPM does not take the Objective-C runtime into account during its build.
From swift.org, Platform Support:
Our goal is to provide source compatibility for Swift across all platforms, even though the actual implementation mechanisms may differ from one platform to the next. The primary example is that the Apple platforms include the Objective-C runtime, which is required to access Apple platform frameworks such as UIKit and AppKit. On other platforms, such as Linux, no Objective-C runtime is present, because it isn’t necessary.
The Swift core libraries project aims to extend the cross-platform capabilities of Swift by providing portable implementations of fundamental Apple frameworks (such as Foundation) without dependencies on the Objective-C runtime. Although the core libraries are in an early stage of development, they will eventually provide improved source compatibility for Swift code across all platforms.
I just resolved this issue by linking with this Framework in Xcode.
I don't know how to specify that in the Package.swift file, but for know it works.
Regards

Why is Objective C runtime needed if appl is compiled as native

New to Swift/Objective-c and coming from Java, C# and C++ background. My understanding is that a runtime is needed if the code is non-native as in case of Java or C# an intermediate code is generated which would at Runtime need an environment which translates code to the machine language and we call that a runtime environment (like JRE).
So having read some Q and As on stack overflow it is clear that Swift and Objective-C both are compiled as native binaries. But they need Objective-C runtime to execute them.
I don't know why a runtime is needed if code is already in machine language ?
Is it like a library linked to the program ?
Or Is this objective-C runtime a separate environment which hosts the objective-C/Swift program ? just like JRE ?
Can someone please shed some light on this ?
Thanks,
Ahmed
Many programming languages rely on runtime libraries, including C++. These consist of low-level routines to support the programming language's model on that of the hosting operating system. Objective-C's runtime library implements core features such as dynamic method lookup.
Java and C# require a virtual machine, these are much more involved than runtime libraries.
HTH

Is it possible to compile Objective-C code on a PC?

I would like to start learning Objective-C for future iOS development. I understand that there are many large hurdles in getting an iPhone app to work on a PC but I'm trying to avoid all of that and just get familiar with the Objective-C language itself without all of the added mobile features.
Is there a way to compile Objective-C programs on a PC to learn just the language without any extra iOS features?
Yes, definitely. Have a look at GNUstep - it's a framework that contains the Objective-C runtime library and most of the Foundation classes. You can learn the language very well by using this package with GCC (gobjc) and MinGW on Linux or Windows.

Linux Clang and Objective-C base library

I have been experimenting with Objective-C using GCC + GNUstep on an Ubuntu system.
Now regarding the LLVM Clang compiler, what kind of *step library does it offer? Does it use the GNUstep on the Apple Cocoa? I am mostly interested in the base library - collections, streams, etc. The website doesn't give much information.
Like MKroehnert and puzzle said, neither LLVM Clang nor GCC actually come with a set of frameworks. GCC comes with only a small runtime that doesn't provide NSArray, NSString, not even NSObject.
Frameworks are provided by, for example:
GNUstep
Cocotron
Cocoa
ObjFW
ObjFW is the lightest of them all, but on any UNIX, I'd recommend you go the GNUstep route.
LLVM Clang is a compiler. It is completely independent from the Cocoa / Cocoa Touch frameworks on OS X / iOS, or any other frameworks or platform, for that matter.
Like puzzle said in his answer clang is a compiler like gcc.
On linux you can also use clang instead of gcc together with the GNUstep libraries (which provide the NS* classes you were asking about).
For more information see GNUstep Objc2 FAQ or this blogpost for example.
Like others said, LLVM Clang is just a compiler. But you can have all the modern features of Objective-C 2.0 on Ubuntu using Clang, the modern GNUstep Objective-C 2.0 runtime and GNUstep itself. Have a look here for a how to:
http://wiki.gnustep.org/index.php/GNUstep_under_Ubuntu_Linux
That page is maintained by the GNUstep developers and contains bash scripts to compile and install everything needed for Objective-C 2.0 from scratch for different versions of Ubuntu-Linux using Clang and the GNUstep Objective-C runtime, which can be found here: https://github.com/gnustep/libobjc2 . It would be moot to copy those lengthy scripts to Stackoverflow since they would get out of date sooner or later. So follow that link to get everything from first hand.