This document provides an overview of how to transition between iOS and Android development by comparing key concepts and technologies. It discusses native programming languages and data types, classes and structs/data classes, enums, extensions, optionals, lazy properties, frameworks like UIKit/Activity and their lifecycles, assets, intents/segues, tables/recyclers, dependency managers like CocoaPods/Gradle, and encourages staying curious across mobile platforms.
3. Who are you?
how many native iOS dev?
3
how many native Android dev?
how mobile hybrid dev?
4. What courses?
Developing iOS 11 Apps with Swift
Paul Hegarty
https://itunes.apple.com/us/podcast/developing-i
os-11-apps-with-swift/id1315130780
Developing Android apps
4
8. Constants & Variables
let name: String = "Giuseppe"
var age: Int = 32
8
val name: String = "Giuseppe"
var age: Int = 32
let name = "Giuseppe"
var age = 32
val name = "Giuseppe"
var age = 32
Type inference
9. Classes
class Person {
let name: String
init(name: String) {
self.name = name
}
}
let aPerson = Person(name: "Giuseppe")
print(aPerson.name)
9
class Person(val name: String)
val aPerson = Person("Giuseppe")
print(aPerson.name)
10. How to hold data
struct Person {
let name: String
let surname: String
var age: Int
}
let aPerson = Person(name: "Giuseppe",
surname: "Filograno", age: 32)
10
data class Person(val name: String, val
surname: String, var age: Int)
val aPerson = Person("Giuseppe",
"Filograno", 32)
● No inheritance
● Passed by value
● Default initializer
No inheritance and automatically implements:
● equals()/hashCode() pair
● toString() of the form
"Person(name=Giuseppe,
surname=Filograno, age=32)"
● componentN() functions corresponding to
the properties in their order of declaration
● copy() function
11. Enums
enum Suit {
case spades, hearts, diamond, clubs
func simpleDescription() -> String {
switch self {
case .spades: return "spades"
case .hearts: return "hearts"
case .diamond: return "diamond"
case .clubs: return "clubs"
}
}
}
let hearts = Suit.hearts
print(hearts.simpleDescription())
enum class Suit {
spades, hearts, diamond, clubs;
fun simpleDescription(): String {
return when (this) {
Suit.spades -> "spades"
Suit.hearts -> "hearts"
Suit.diamond -> "diamonds"
Suit.clubs -> "clubs"
}
}
}
val hearts = Suit.hearts
print(hearts.simpleDescription())
11
13. Extensions
extension Double {
var km: Double { return self * 1_000.0 }
var mm: Double { return self / 1_000.0 }
var ft: Double { return self / 3.28084 }
}
let oneInch = 25.4.mm
print("One inch is (oneInch) meters")
// Prints "One inch is 0.0254 meters"
let threeFeet = 3.ft
print("Three feet is (threeFeet) meters")
// Prints "Three feet is 0.914399970739201 meters"
val Double.km
get() = this * 1000.0
val Double.mm
get() = this / 1_000.0
val Double.ft
get() = this / 3.28084
val oneInch = 25.4.mm
print("One inch is ${oneInch} meters")
// Prints "One inch is 0.0254 meters"
val threeFeet = 3.0.ft
print("Three feet is ${threeFeet} meters")
// Prints "Three feet is 0.914399970739201
meters"
13
14. Optionals
var aNumber: Int = 42
var optionalNumber: Int? = nil
optionalNumber = 42
optionalNumber?.negate()
optionalNumber!.negate()
var aNumber: Int = 42
var optionalNumner: Int? = null
optionalNumner = 42
val incrementedNumber = optionalNumner?.inc()
val numberPlusPlus = optionalNumner!!.inc()
14
15. If let
var optionalNumber: Int? = nil
if let number = optionalNumber {
let incrementedNumber =
number.advanced(by: 1)
print(incrementedNumber)
}
optionalNumber?.let {
val incrementedNumber = it.inc()
print(incrementedNumber)
}
15
16. Lazy Stored Properties
A lazy stored property is a property whose initial
value is not calculated until the first time it is
used. You indicate a lazy stored property by
writing the lazy modifier before its declaration.
class DataManager {
lazy var importer = DataImporter()
var data = [String]()
}
let manager = DataManager()
manager.data.append("Some data")
manager.data.append("Some more data")
// the DataImporter instance for the importer
property has not yet been created
lazy() is a function that takes a lambda and
returns an instance of Lazy<T> which can serve
as a delegate for implementing a lazy property:
the first call to get() executes the lambda passed
to lazy() and remembers the result, subsequent
calls to get() simply return the remembered
result.
class DataManager {
val importer by lazy { DataImporter() }
var data = mutableListOf<String>()
}
val manager = DataManager()
manager.data.add("Some data")
manager.data.add("Some more data")
16
20. IBOutlet, IBAction vs ...
Outlets provide a way to reference interface objects from source code files.
An action (or an action method) is a piece of code that’s linked to an event that can
occur in your app.
20
23. Asset Catalog
Asset catalogs simplify access to app resources by mapping between named assets and one
or more files targeted for different device attributes.
23
25. UIStoryboardSegue
An object that prepares for and performs the
visual transition between two view controllers.
Explicit Intent
An Intent is a messaging object you can use to
request an action from another app component.
val intent = Intent(this,
ActivityB::class.java)
val myString = editText.text.toString()
intent.putExtra("qString", myString)
startActivity(intent)
25
26. UITableView
A table view displays a list of items in a single
column. UITableView is a subclass of
UIScrollView, which allows users to scroll
through the table, although UITableView allows
vertical scrolling only.
RecyclerView
26
27. UITableViewDataSource
It’s a protocol adopted by an object that mediates
the application’s data model for a UITableView
object. The data source provides the table-view
object with the information it needs to construct and
modify a table view.
RecyclerView.Adapter
It's an abstract class that provide a binding from
an app-specific data set to views that are
displayed within a RecyclerView.
27
func tableView(_ tableView: UITableView, cellForRowAt
indexPath: IndexPath) -> UITableViewCell {
let cell =
tableView.dequeueReusableCell(withIdentifier:
"LabelCell", for: indexPath)
cell.textLabel?.text = "Row (indexPath.row)"
return cell
}
func tableView(UITableView,
numberOfRowsInSection: Int) -> Int
fun getItemCount(): Int
fun onCreateViewHolder(parent:
ViewGroup?, viewType: Int): ViewHolder
fun onBindViewHolder(holder:
ViewHolder?, position: Int)
28. Cocoapods
CocoaPods is a dependency manager for Swift
and Objective-C Cocoa projects. It has over 52
thousand libraries and is used in over 3 million
apps.
Gradle
Gradle has built-in support for dependency
management and lives up the task of fulfilling
typical scenarios encountered in modern
software projects.
28
target 'MyApp' do
use_frameworks!
pod 'Alamofire', '~> 3.0'
end
pod install //generates a Podfile.lock
dependencies {
implementation fileTree(dir: 'libs',
include: ['*.jar'])
implementation
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kot
lin_version"
implementation
"com.android.support:recyclerview-v7:28.0.0"
}
30. Final considerations
● Android and iOS development worlds seem not so different!
● Don’t reject other (mobile) technologies
● Stay curious!
● To study a slightly different technology helps you to better understand your
core technology
30