Where exactly is the issue with ABI stability in Swift programming - swift

First of all, I've been an Objective C developer for years, and around the time that Swift was announced I was mostly maintaining existing Obj C projects. The chance never came to be fully invested in a Swift app, whether from scratch or to maintain. My efforts where directed mostly towards .Net and React Native at that time.
I've done research on what ABI is. It's all fine and dandy. From that answer, I can only assume how that comes into play for Swift, since I do not have much heavy involvement with Swift.
So, from simply guessing, is all the ruckus, racket, and fracas in Swift ABI talk to do with the 'assumed' fact that when a library is written/compiled with version 1.0 of Swift (before Swift 5), it will work fine with an app written in 1.0. When the next version of that library is written in Swift 2.0, that aforementioned app written in Swift 1.0 will not be able to use it, unless compiled for Swift 2.0? Assuming that I am correct on that one, what if I have an app written in Swift 4, and the library I wish to use was written in Swift 1.0 Can I use it? With Swift 5 now released, are ABI issues now resolved for Swift libraries and apps 5+, and not 5+ interacting with 5- ?
If I had experienced these issues first hand I might have had a better understanding of Swift ABI issues.
Please explain with actual examples that cover the full range of cases (if possible).
Update: please include if there are any issues with ABI for small version increases eg from swift 4.0 to 4.1

The chiefly interesting thing to know about ABI stability is that for systems before iOS 10.2 and Swift language versions before 5.0, the Swift language frameworks have to be embedded in the app, adding several MB to its size and perhaps some other runtime overhead. But in iOS 10.2+ and Swift 5.0+, now that there is ABI stability, that stuff is in the runtime and Swift apps are much smaller, probably faster, and quicker to launch.
In other words, thanks to ABI stability, Swift is now the first class citizen that Objective C and Cocoa have been all along.

Application Binary Interface. ABI stability for Swift is about compiling source code into binary files with a common interface over several versions of the language. Without an ABI stability, the binary files across versions of the language, are incompatible with each other, because their formats differ. Dynamic libraries, for instance, have a static call table. As quoted from Wikipedia: "An ABI defines how data structures or computational routines are accessed in machine code". An ABI stability ensures that the library and caller (the app) use the same binary protocol for invoking functions, even if not compiled for the same version of the language.
For Swift's purpose, an ABI stability will allow developers to switch to newer versions of the language, without updating their libraries/frameworks, that way taking advantage of the newer features of the language without waiting for the libraries to get updated. From a Swift.org article back in February: "Today, when a Swift library changes, any apps using that library have to be recompiled." Again, from that article:
ABI stability for Apple OSes means that apps deploying to upcoming releases of those OSes will no longer need to embed the Swift standard library and “overlay” libraries within the app bundle, shrinking their download size; the Swift runtime and standard library will be shipped with the OS, like the Objective-C runtime.
For you as a developer, ABI stability in Swift, means more compatibility with libraries. Due to the Swift language developers needing to ensure that the ABI stability doesn't break, the rate of addition of new features will drop.

Related

How to access all Swift standard lib source code or module definitions from within Xcode?

Currently we can access a particular module in Swift by command + clicking a particular Swift type. Is there a way to easily access all Swift modules / standard libraries from within Xcode?
Is there a way to debug into Swift source code like one can in Android?
Is there a way to debug into Swift source code like one can in Android?
The answer depends on what you mean by "all Swift modules / standard libraries".
If you are interested in the Swift's standard libraries (i.e. clases like String or Array), then Swift was open-sourced by Apple and you can find sources on github following links from https://swift.org/source-code/. Still there seems to be no way to "attach" those sources to navigate there from your XCode project.
However, if you are interested in most of the MacOS or iOS frameworks such as UIKit and many others, then I believe the answer is NO.
Unlike Android, iOS is a proprietary closed source OS and in most of the areas Apple has no intentions to share its code with everyone.
Side Note: Once it was claimed that one of major reasons for Apple to switch its tools from GCC stack to Clang/LLVM stack was that GCC is licensed under "copyleft" GPL and thus Apple couldn't integrate parts of GCC Obj-C backend (such as code analysis or stuff useful for refactoring) into XCode even if those parts were developed by Apple itself without making whole XCode open source. Clang/LLVM on the other hand uses more permissive open-source license that allows such 3rd-party usages.
Moreover much of the Apple's internal code still must be in Objective-C or even plain C rather than Swift. It is relatively easy to convert "headers" i.e. interfaces specification from Obj-C to Swift automatically but it is very hard for real implementation especially given difference between Obj-C and Swift. So even if it was an open-source, there would be no debugging in Swift.
On a positive side: some code gets executed and Apple can't hide it and thus you can debug it. The only problem is that the code is in machine language helpfully decoded into Assembly (x86 or ARM) by XCode. However, it obviously requires some skill and time to understand any non-trivial logic from that. And beware that you probably can't copy logic found that way without violating some copyright laws.
Swift is open source. So you can get its code and modules here.
However, you can't do it with command + clicking in Xcode from your own project. In fact, the code you got from command + clicking was not Swift source. They were headers that were generated by the compiler automatically. Those headers may be generated from Swift source code, or even Objective-C code.
Also, even though you can get source code and edit it, you can't use it on your app that you want to be published to App Store. You can only use the Swift comes with Xcode to published to App Store, or your app will be rejected.

Is it possible to add Swift sources to Xcode? If yes, how?

Now that Swift is open source and that they released some libraries' sources like Foundation, I was wondering how I could add those into Xcode so that I can for example have a look into NSString (even String?) for any project I would create without adding sources as libraries every time.
A way to have access to the .swift file and not the public ".h" version.
The open-source release of Swift includes Foundation and other core libraries... but these are not the same libraries that you get when developing for Apple platforms with Xcode and its included SDKs.
On iOS (and other Apple platforms), Foundation is built in Objective-C. When you develop in Swift using Xcode SDKs, the Swift runtime automatically bridges calls to/from ObjC code. Apple does not publish the source code for this version of Foundation.
When you build with open-source Swift for non-Apple platforms (e.g. Linux), you get the open-source, entirely-Swift version of Foundation instead. This is an completely separate project, which aims to provide Swift equivalents of most of the key primitive and utility class from the original Foundation. (And it's currently incomplete.)
The idea here is that one should be able to write Swift code that makes use of NSURL, NSDate, NSFileManager, NSFormatter, NSString (i.e. the set of rich, internationalized string handling features beyond the basics that Swift.String provides), et cetera, and have it work regardless of whether that code gets built with Xcode for Apple platforms or with open-source Swift for other platforms. So the APIs are the same, but the implementations are different.
However, both implementations of Foundation rely on lower-level libraries that are open source. The most basic parts of Foundation are provided by CoreFoundation — a C library that's been part of Apple's Darwin open source releases for many years. Other parts use the International Components for Unicode library, libdispatch, and libxml2.
Anyhow... when you're working in a Swift project in Xcode, the Jump to Definition (Cmd-click) feature should get you to the Swift interfaces for ObjC classes in the SDK, not the ObjC headers for those classes. There isn't a handy way to make Xcode look up the actual source code for those classes (where they happen to be open source), but you can follow the links above.

Minimum iOS version that supports c++ 0x

I have small game engine written in c++. I'm considering using some features of c++0x
What minimum version of ios required? Does the new standard comes as an additional dynamic library or is it just statically linked?
Update:
I'm planning to use lambdas, new for cycle and auto type deduction
Mooing Duck:
I want both make and run.
C++11 support on iOS is pretty much restricted to the Clang compiler, which has been slowly adding C++11 features over several releases. The standard library on iOS that supports C++11 is libc++, and it is dynamically linked, so new features that need standard library support are going to have minimum SDK versions. It wasn't really until iOS 5 that Apple felt comfortable saying that C++11 is supported by the compiler, but some features were available before then. Ultimately, it depends on what feature you're considering, and the simplest way to find out (since I'm not aware of any laundry list of features and which versions of iOS they work on) is simply to make a small test case and try to build it against various iOS SDK versions.

What programming languages can one use to develop iPhone, iPod Touch and iPad (iOS) applications?

What programming languages can one use to develop iPhone, iPod Touch and iPad (iOS) applications?
Also are there plans in the future to expand the amount of programming languages that iOS will support?
Apple lifted the restrictions on non-Objective C/C/C++ apps -- you just can't load code that isn't in the app bundle.
MonoTouch lets you use .NET languages -- C# is directly supported, but if you have Windows, you can make assemblies in any .NET language and use it.
There are rumors that Apple is going to support other languages directly -- I keep hearing ruby, but they are just rumors.
I think Lua is being used for game logic on a lot of apps.
EDIT (in 2018): Generally you can use any language that you can get to compile for iOS or even install language interpreters. The main thing you cannot do is load code from the Internet that wasn't in the app bundle.
People do this all of the time anyway (see React Native apps loading JavaScript from servers), but, technically, it's not allowed. The main thing that will get you attention from Apple if you make some kind of App Store that loads whole App-like things.
EDIT (in 2020): from #Pylot in comments: I know this is a long time ago, but now at least technically you can load code that isn’t embedded in the app, as you can write with JavaScript using the webview. Not staying your answer is wrong or anything, I definitely agree with you. but I was looking for something and found this post on the way. Figured if anyone sees this it might help them out.
The SDK agreement and App store guidelines have been changed (circa Sept 2010).
You can now probably use any compiled language that will compile to the same static ARM object file format as Xcode produces and that will link to (only) the public API's within Apple's frameworks and libraries. However, you can not use a JIT compiled language unless you pre-compile all object code before submission to Apple for review.
You can use any interpreted language, as long as you embed the interpreter, and do not allow the interpreter or the app to download and run any interpretable code other than code built into the app bundle before submission to Apple for review, or source code typed-in by the user.
Objective C and C will likely still be the most optimal programming language for anything requiring high performance and the latest API support (* see update below), as those are the languages for which Apple targets its iOS frameworks and tunes its ARM processor chipsets. Apple also supports the use of Javascript/HTML5 inside a UIWebView. Those are the only languages for which Apple has announced support. Anything else you will have to find support elsewhere.
But, if you really want, there are at least a half dozen BASIC interpreters now available in the iOS App store, so even "Stone Age" programming methodology is now allowed.
Added: (*) As of late 2014, one can also develop apps using Apple's new Swift programming language. As of early 2015, submitted binaries must include 64-bit (arm64) support.
With plans to slowly retire the long-used Objective-C, Apple has introduced a new programming language, called Swift, for designing apps and applications to run on Apple iOS devices and Apple Macintosh computers.
Apple says:
"Swift is a new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun. Swift’s clean slate, backed by the mature and much-loved Cocoa and Cocoa Touch frameworks, is an opportunity to reimagine how software development works."
Introducing swift
What programming languages can one use to develop iPhone, iPod Touch and iPad (iOs) applications?
Ruby, Python, Lua, Scheme, Lisp, Smalltalk, C#, Haskell, ActionScript, JavaScript, Objective-C, C++, C. That's just the ones that pop into my head right now. I'm sure there's hundreds if not thousands of others. (E.g. there's no reason why you couldn't use any .NET language with MonoTouch, i.e. VB.NET, F#, Nemerle, Boo, Cobra, ...)
Also are there plans in the future to expand the amount of programming languages that iOs will support?
Sure. Pretty much every programming language community on this planet is currently working on getting their language to run on iOS.
Also, a lot of people are working on programming languages specifically designed for touch devices such as iPod touch, iPhone and iPad, e.g. Phil Mercurio's Thyrd language.
The programming language of iOS(and Mac OS) is Objective-C and C. You have to use Xcode platform to develop iOS apps, on the next version that is now available on beta release, Xcode 4 supports also C++.
It is also now possible to use OCaml for developing iOS applications. It is not part of the standard distribution and requires modifications provided by the Psellos company. See here for more information: http://psellos.com/ocaml/.
This might be an old thread, but I'd like to mention Appcelerator Titanium, which allows anyone versed in HTML5/JavaScript/CSS to develop iOS applications.
Only Objective-C is allowed by now... but since a few months ago you are allowed to write scripts that will be interpreted in your application.
So you may be able to write a LUA interpreter or a Python interpreter, then write some part of your application in this scripting language. If you want your application accepted on the App Store, these scripts have to be bundled with the application (your application cannot download it from the Internet for example)
see new app store rules
objective-c is the primary language used.
i believe there is a mono touch framework that can be used with c#
Adobe also is working in some tools, one is this iPhone Packager which can utilize actionscript code
You can use "smart BASIC" programming language. It is a genuine but very advanced BASIC language with all its power and simplicity. Using its free SDK, BASIC code can be easily published as a standalone App Store application. There are many apps in App Store, written in "smart BASIC" programming language.

Which is the most supported programming language for the iPhone?

I have decided to start programming some apps for the iPhone that eventually will get submitted to App Store. So I have to use a language the Apple supports.
However, from what I understand, there are some variety of languages I can choose from.
Ansi C
Objective C
C
C++
I started learning C++ in school back in 2001, so maybe I should use that. However, I would like to use the language that is most supported API and community wize. Which one is that?
Here's the low-down:
All iPhone SDK APIs are either Objective-C or pure (ANSI) C. The pure C APIs tend to be the lower-level APIs, so you could use just Objective-C.
However Objective-C is a strict superset of C, so you'll need a reasonable grounding in C in order to write Objective-C.
C++ is fully supported, but is not required (there are no C++ APIs). You can even mix Objective-C and C++ in the same source using Objective-C++. If you do this it's best to use C++ for pure computational components, pure Objective-C for the front-end, and Objective-C++ for the "glue" layer in the middle.
In summary: you'll need C and Objective-C. Use C++ for some parts if you particularly need it.
objective-c is the most supported - all the examples use it
Main language for iPhone platform is objective-c - almost all frameworks are objective-c based so you will have to use it for UI part at least. However as objective-c is a superset of c language you will be able to write some parts of your program using c/c++ as well.
There are C and Objective-C frameworks. Quartz2D is written in C but the Cocoa Touch framework is written in Objective-C, for instance. As Objective-C is a superset of C, if you choose Objective-C you will be able to use all available frameworks without problems.
Depending on what type of applications you're gonna to write, you could save yourself a lot of time & headache and use Appcelerator's Titanium Mobile (JavaScript) or Rhomobile (Ruby). All according to Apples latest TOU and therefore still submittable to the App Store.
The only languages that are officially allowed by Apple are
JavaScript
Objective-C
C++
C
All other languages are not allowed.
Whether or not this restriction is legal is a totally different question. (My gut feeling says that, at least in countries with somewhat sane anti-trust laws, it's illegal.)