This repository contains set of questions for a self-check based on the book "Using Swift with Cocoa and Objective-C (Swift 3 beta)".
- Getting Started
- - Basic Setup
- - Understanding the Swift Import Process
- Interoperability
- - Initialization
-
What is the minimum deployment target for an app made with Swift 3.0/Xcode 8?
Answer:
iOS 7 or OS X 10.9. Setting an earlier deployment target results in a build failure.
-
Does Swift executables built from the command line have the runtime statically linked?
Answer:
No, if you plan to ship a Swift executable built from the command line, you'll need to ship the Swift dynamic libraries as well.
-
Which Objective-C frameworks and C libraries can be imported into Swift and how?
Answer:
Any framework or library that supports modules can be imported. This includes all of the Objective-C system frameworks. It can be imported simply by adding import statement to top of the file:
import Foundation
-
How to import C++ code into Swift?
Answer:
It isn't possible to import C++ code directly into Swift. Instead you need to create an Objective-C or C wrapper for C++ code.
-
Let's say you have an Objective-C class Person with initializer listed in a code below. This class imported into Swift code. How do you instantiate this Person in Swift?
- (instancetype)initWithName:(NSString *)name age:(NSInteger)age;
Answer:
let bob: Person = Person(name: "Bob Novado", age: 40) // or you can omit the type and let Swift to infer it let bob = Person(name: "Bob Novado", age: 40)
-
How does Objective-C class factory methods imported into Swift?
Answer:
They imported as convinience initializers, like:
let color = UIColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.5) // instead of [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5]