Skip to content

Instantly share code, notes, and snippets.

@mschmulen
Last active February 8, 2019 15:16
Show Gist options
  • Save mschmulen/7b4d8a93697b3cbf6682e4d7778775de to your computer and use it in GitHub Desktop.
Save mschmulen/7b4d8a93697b3cbf6682e4d7778775de to your computer and use it in GitHub Desktop.
Kotlin for swift developers

Overview

KotlinLang vs Swift

Syntax (slight differences):

Swift Kotlin Notes
let val immutable
var var mutable
nil null undefined
func fun function
protocol trait abastract/virtual
init constructor initialization
-> : return value
Any AnyObject
! !! force unwrap
-> : return value
print println

similarities:

lang:

  • Eplicit Types: var name:String = "matt"
  • Type Coercion: val age = 2
  • Typing: both strong and static
  • String Interpolation: var message = "$matt scored a ${score} " + "today."
  • Rang Operators (Inclusive): for i in 0..<count { vs for (i in 0..count - 1) {
  • Etensions
  • Map, Filter, Reduce:
  • vargs
  • Tuple support: fun myTupel = (2,3,5)
  • Supports Optionals: val name:String? = null explicity unwrap: name!! optional unwrap name?
  • Closer/lambda support
  • Name parameters (arguments)
  • Computed properties get{ "hello" } and get() = "hello"
  • switch when () {

Arrays (similar-ish, Kotlin Array vs Kotlin ArrayList ):

  • Kotlin (mutable fixed size): val numbers = Array<Int>(5){0}
  • Kotlin (mutable array, variable size): var names = ArrayList<String>()
  • Kotlin (immutable array): val days = arrayOf("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")

Dictionaries Maps (similar-ish, HashMap vs mapOf):

  • Kotlin (variable capacity):var namesWithAges = HashMap<String, Int>()
  • Kotlin (fixed capacity): var namesWithAges = HashMap<String, Int>(20) //
  • similar assignment. Kotlin: namesWithAges["John Doe"] = 34
  • Kotlin (immutable): val namesWithAges = mapOf("John Doe" to 34, "Jane Doe" to 29)

concept of mutability and immutability properties:

  • mutable properties: var vs var
  • immutable Properties: let vs val

differences:

swift supports (kotlin does not):

  • guard
  • typealias
  • tuples ( kotlin onlys supports tuples as return types)

kotlin supports (swift does not):

  • guard

  • class specific importation class import

  • @annotations

  • data classes vs struct (value types)

  • kotlin classes are final by default

  • memory allocation ?

  • functional closers? un-winding?

Things to investigate:

  • kotlin has no semantic for passing data by value ( struct ) ? Im not 100% sure if this is true

iOS vs Android

  • UIViewController vs Activity
  • UIView vs View/Widget
  • Storyboard/xib vs xml layout
  • segue vs intent
  • simulator vs emulator
  • 2x,3x vs mdpi,hdpi,...
  • gradle vs pods

Misc

  • Kotlin supports targets: ( JVM, Objective-C, JavaScript)
  • json vs gson vs jxson : faster?

Learning Resources

Kotlin Web Playground

https://kotlinlang.org/

https://web.stanford.edu/class/cs193a/videos.shtml

https://adorahack.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment