├── code ├── hello-world.kt ├── sort.kt ├── hello-world.swift ├── explicit-types.swift ├── explicit-types.kt ├── map.kt ├── map.swift ├── sort.swift ├── variables-and-constants.swift ├── variables-and-constants.kt ├── empty-collections.swift ├── type-coercion.kt ├── empty-collections.kt ├── tuple-return.swift ├── type-coercion.swift ├── usage.kt ├── usage.swift ├── arrays.swift ├── arrays.kt ├── named-arguments.swift ├── functions.kt ├── maps.swift ├── tuple-return.kt ├── declaration.kt ├── protocol.kt ├── functions.swift ├── maps.kt ├── protocol.swift ├── string-interpolation.swift ├── string-interpolation.kt ├── declaration.swift ├── downcasting.kt ├── downcasting.swift ├── variable-number-of-arguments.swift ├── named-arguments.kt ├── inclusive-range-operator.kt ├── inclusive-range-operator.swift ├── checking-type.swift ├── function-type.swift ├── checking-type.kt ├── pattern-matching.kt ├── pattern-matching.swift ├── range-operator.swift ├── range-operator.kt ├── variable-number-of-arguments.kt ├── function-type.kt ├── extensions.kt ├── extensions.swift ├── subclass.kt └── subclass.swift ├── .gitignore ├── README.md ├── make.coffee ├── package.json ├── css ├── highlightjs-github.css └── style.css ├── cirru └── index.cirru └── js └── highlight.9.4.0.js /code/hello-world.kt: -------------------------------------------------------------------------------- 1 | println("Hello, world!") 2 | -------------------------------------------------------------------------------- /code/sort.kt: -------------------------------------------------------------------------------- 1 | listOf(1, 5, 3, 12, 2).sorted() 2 | -------------------------------------------------------------------------------- /code/hello-world.swift: -------------------------------------------------------------------------------- 1 | print("Hello, world!") 2 | -------------------------------------------------------------------------------- /code/explicit-types.swift: -------------------------------------------------------------------------------- 1 | let explicitDouble: Double = 70 -------------------------------------------------------------------------------- /code/explicit-types.kt: -------------------------------------------------------------------------------- 1 | val explicitDouble: Double = 70.0 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | index.html 3 | .DS_Store 4 | *~ 5 | \#*# 6 | -------------------------------------------------------------------------------- /code/map.kt: -------------------------------------------------------------------------------- 1 | val numbers = listOf(20, 19, 7, 12) 2 | numbers.map { 3 * it } 3 | -------------------------------------------------------------------------------- /code/map.swift: -------------------------------------------------------------------------------- 1 | let numbers = [20, 19, 7, 12] 2 | numbers.map { 3 * $0 } 3 | -------------------------------------------------------------------------------- /code/sort.swift: -------------------------------------------------------------------------------- 1 | var mutableArray = [1, 5, 3, 12, 2] 2 | mutableArray.sort() 3 | -------------------------------------------------------------------------------- /code/variables-and-constants.swift: -------------------------------------------------------------------------------- 1 | var myVariable = 42 2 | myVariable = 50 3 | let myConstant = 42 -------------------------------------------------------------------------------- /code/variables-and-constants.kt: -------------------------------------------------------------------------------- 1 | var myVariable = 42 2 | myVariable = 50 3 | val myConstant = 42 4 | -------------------------------------------------------------------------------- /code/empty-collections.swift: -------------------------------------------------------------------------------- 1 | let emptyArray = [String]() 2 | let emptyDictionary = [String: Float]() 3 | -------------------------------------------------------------------------------- /code/type-coercion.kt: -------------------------------------------------------------------------------- 1 | val label = "The width is " 2 | val width = 94 3 | val widthLabel = label + width 4 | -------------------------------------------------------------------------------- /code/empty-collections.kt: -------------------------------------------------------------------------------- 1 | val emptyArray = arrayOf<String>() 2 | val emptyMap = mapOf<String, Float>() 3 | -------------------------------------------------------------------------------- /code/tuple-return.swift: -------------------------------------------------------------------------------- 1 | func getGasPrices() -> (Double, Double, Double) { 2 | return (3.59, 3.69, 3.79) 3 | } -------------------------------------------------------------------------------- /code/type-coercion.swift: -------------------------------------------------------------------------------- 1 | let label = "The width is " 2 | let width = 94 3 | let widthLabel = label + String(width) -------------------------------------------------------------------------------- /code/usage.kt: -------------------------------------------------------------------------------- 1 | var shape = Shape() 2 | shape.numberOfSides = 7 3 | var shapeDescription = shape.simpleDescription() 4 | -------------------------------------------------------------------------------- /code/usage.swift: -------------------------------------------------------------------------------- 1 | var shape = Shape() 2 | shape.numberOfSides = 7 3 | var shapeDescription = shape.simpleDescription() -------------------------------------------------------------------------------- /code/arrays.swift: -------------------------------------------------------------------------------- 1 | var shoppingList = ["catfish", "water", 2 | "tulips", "blue paint"] 3 | shoppingList[1] = "bottle of water" -------------------------------------------------------------------------------- /code/arrays.kt: -------------------------------------------------------------------------------- 1 | val shoppingList = arrayOf("catfish", "water", 2 | "tulips", "blue paint") 3 | shoppingList[1] = "bottle of water" 4 | -------------------------------------------------------------------------------- /code/named-arguments.swift: -------------------------------------------------------------------------------- 1 | func area(width: Int, height: Int) -> Int { 2 | return width * height 3 | } 4 | area(width: 2, height: 3) 5 | -------------------------------------------------------------------------------- /code/functions.kt: -------------------------------------------------------------------------------- 1 | fun greet(name: String, day: String): String { 2 | return "Hello $name, today is $day." 3 | } 4 | greet("Bob", "Tuesday") 5 | -------------------------------------------------------------------------------- /code/maps.swift: -------------------------------------------------------------------------------- 1 | var occupations = [ 2 | "Malcolm": "Captain", 3 | "Kaylee": "Mechanic", 4 | ] 5 | occupations["Jayne"] = "Public Relations" -------------------------------------------------------------------------------- /code/tuple-return.kt: -------------------------------------------------------------------------------- 1 | data class GasPrices(val a: Double, val b: Double, 2 | val c: Double) 3 | fun getGasPrices() = GasPrices(3.59, 3.69, 3.79) 4 | -------------------------------------------------------------------------------- /code/declaration.kt: -------------------------------------------------------------------------------- 1 | class Shape { 2 | var numberOfSides = 0 3 | fun simpleDescription() = 4 | "A shape with $numberOfSides sides." 5 | } 6 | -------------------------------------------------------------------------------- /code/protocol.kt: -------------------------------------------------------------------------------- 1 | interface Nameable { 2 | fun name(): String 3 | } 4 | 5 | fun f<T: Nameable>(x: T) { 6 | println("Name is " + x.name()) 7 | } 8 | -------------------------------------------------------------------------------- /code/functions.swift: -------------------------------------------------------------------------------- 1 | func greet(_ name: String,_ day: String) -> String { 2 | return "Hello \(name), today is \(day)." 3 | } 4 | greet("Bob", "Tuesday") 5 | -------------------------------------------------------------------------------- /code/maps.kt: -------------------------------------------------------------------------------- 1 | val occupations = mutableMapOf( 2 | "Malcolm" to "Captain", 3 | "Kaylee" to "Mechanic" 4 | ) 5 | occupations["Jayne"] = "Public Relations" 6 | -------------------------------------------------------------------------------- /code/protocol.swift: -------------------------------------------------------------------------------- 1 | protocol Nameable { 2 | func name() -> String 3 | } 4 | 5 | func f<T: Nameable>(x: T) { 6 | print("Name is " + x.name()) 7 | } 8 | -------------------------------------------------------------------------------- /code/string-interpolation.swift: -------------------------------------------------------------------------------- 1 | let apples = 3 2 | let oranges = 5 3 | let fruitSummary = "I have \(apples + oranges) " + 4 | "pieces of fruit." -------------------------------------------------------------------------------- /code/string-interpolation.kt: -------------------------------------------------------------------------------- 1 | val apples = 3 2 | val oranges = 5 3 | val fruitSummary = "I have ${apples + oranges} " + 4 | "pieces of fruit." 5 | -------------------------------------------------------------------------------- /code/declaration.swift: -------------------------------------------------------------------------------- 1 | class Shape { 2 | var numberOfSides = 0 3 | func simpleDescription() -> String { 4 | return "A shape with \(numberOfSides) sides." 5 | } 6 | } -------------------------------------------------------------------------------- /code/downcasting.kt: -------------------------------------------------------------------------------- 1 | for (current in someObjects) { 2 | if (current is Movie) { 3 | println("Movie: '${current.name}', " + 4 | "dir. ${current.director}") 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /code/downcasting.swift: -------------------------------------------------------------------------------- 1 | for current in someObjects { 2 | if let movie = current as? Movie { 3 | print("Movie: '\(movie.name)', " + 4 | "dir. \(movie.director)") 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /code/variable-number-of-arguments.swift: -------------------------------------------------------------------------------- 1 | func sumOf(_ numbers: Int...) -> Int { 2 | var sum = 0 3 | for number in numbers { 4 | sum += number 5 | } 6 | return sum 7 | } 8 | sumOf(42, 597, 12) 9 | -------------------------------------------------------------------------------- /code/named-arguments.kt: -------------------------------------------------------------------------------- 1 | fun area(width: Int, height: Int) = width * height 2 | area(width = 2, height = 3) 3 | 4 | // This is also possible with named arguments 5 | area(2, height = 2) 6 | area(height = 3, width = 2) 7 | -------------------------------------------------------------------------------- /code/inclusive-range-operator.kt: -------------------------------------------------------------------------------- 1 | for (index in 1..5) { 2 | println("$index times 5 is ${index * 5}") 3 | } 4 | // 1 times 5 is 5 5 | // 2 times 5 is 10 6 | // 3 times 5 is 15 7 | // 4 times 5 is 20 8 | // 5 times 5 is 25 9 | -------------------------------------------------------------------------------- /code/inclusive-range-operator.swift: -------------------------------------------------------------------------------- 1 | for index in 1...5 { 2 | print("\(index) times 5 is \(index * 5)") 3 | } 4 | // 1 times 5 is 5 5 | // 2 times 5 is 10 6 | // 3 times 5 is 15 7 | // 4 times 5 is 20 8 | // 5 times 5 is 25 -------------------------------------------------------------------------------- /code/checking-type.swift: -------------------------------------------------------------------------------- 1 | var movieCount = 0 2 | var songCount = 0 3 | 4 | for item in library { 5 | if item is Movie { 6 | movieCount += 1 7 | } else if item is Song { 8 | songCount += 1 9 | } 10 | } -------------------------------------------------------------------------------- /code/function-type.swift: -------------------------------------------------------------------------------- 1 | func makeIncrementer() -> (Int -> Int) { 2 | func addOne(number: Int) -> Int { 3 | return 1 + number 4 | } 5 | return addOne 6 | } 7 | let increment = makeIncrementer() 8 | increment(7) 9 | -------------------------------------------------------------------------------- /code/checking-type.kt: -------------------------------------------------------------------------------- 1 | var movieCount = 0 2 | var songCount = 0 3 | 4 | for (item in library) { 5 | if (item is Movie) { 6 | ++movieCount 7 | } else if (item is Song) { 8 | ++songCount 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /code/pattern-matching.kt: -------------------------------------------------------------------------------- 1 | val nb = 42 2 | when (nb) { 3 | in 0..7, 8, 9 -> println("single digit") 4 | 10 -> println("double digits") 5 | in 11..99 -> println("double digits") 6 | in 100..999 -> println("triple digits") 7 | else -> println("four or more digits") 8 | } 9 | -------------------------------------------------------------------------------- /code/pattern-matching.swift: -------------------------------------------------------------------------------- 1 | let nb = 42 2 | switch nb { 3 | case 0...7, 8, 9: print("single digit") 4 | case 10: print("double digits") 5 | case 11...99: print("double digits") 6 | case 100...999: print("triple digits") 7 | default: print("four or more digits") 8 | } 9 | -------------------------------------------------------------------------------- /code/range-operator.swift: -------------------------------------------------------------------------------- 1 | let names = ["Anna", "Alex", "Brian", "Jack"] 2 | let count = names.count 3 | for i in 0..<count { 4 | print("Person \(i + 1) is called \(names[i])") 5 | } 6 | // Person 1 is called Anna 7 | // Person 2 is called Alex 8 | // Person 3 is called Brian 9 | // Person 4 is called Jack 10 | -------------------------------------------------------------------------------- /code/range-operator.kt: -------------------------------------------------------------------------------- 1 | val names = arrayOf("Anna", "Alex", "Brian", "Jack") 2 | val count = names.count() 3 | for (i in 0..count - 1) { 4 | println("Person ${i + 1} is called ${names[i]}") 5 | } 6 | // Person 1 is called Anna 7 | // Person 2 is called Alex 8 | // Person 3 is called Brian 9 | // Person 4 is called Jack 10 | -------------------------------------------------------------------------------- /code/variable-number-of-arguments.kt: -------------------------------------------------------------------------------- 1 | fun sumOf(vararg numbers: Int): Int { 2 | var sum = 0 3 | for (number in numbers) { 4 | sum += number 5 | } 6 | return sum 7 | } 8 | sumOf(42, 597, 12) 9 | 10 | // sumOf() can also be written in a shorter way: 11 | fun sumOf(vararg numbers: Int) = numbers.sum() 12 | -------------------------------------------------------------------------------- /code/function-type.kt: -------------------------------------------------------------------------------- 1 | fun makeIncrementer(): (Int) -> Int { 2 | val addOne = fun(number: Int): Int { 3 | return 1 + number 4 | } 5 | return addOne 6 | } 7 | val increment = makeIncrementer() 8 | increment(7) 9 | 10 | // makeIncrementer can also be written in a shorter way: 11 | fun makeIncrementer() = fun(number: Int) = 1 + number 12 | -------------------------------------------------------------------------------- /code/extensions.kt: -------------------------------------------------------------------------------- 1 | val Double.km: Double get() = this * 1000 2 | val Double.m: Double get() = this 3 | val Double.cm: Double get() = this / 100 4 | val Double.mm: Double get() = this / 1000 5 | val Double.ft: Double get() = this / 3.28084 6 | 7 | val oneInch = 25.4.mm 8 | println("One inch is $oneInch meters") 9 | // prints "One inch is 0.0254 meters" 10 | val threeFeet = 3.0.ft 11 | println("Three feet is $threeFeet meters") 12 | // prints "Three feet is 0.914399970739201 meters" 13 | -------------------------------------------------------------------------------- /code/extensions.swift: -------------------------------------------------------------------------------- 1 | extension Double { 2 | var km: Double { return self * 1_000.0 } 3 | var m: Double { return self } 4 | var cm: Double { return self / 100.0 } 5 | var mm: Double { return self / 1_000.0 } 6 | var ft: Double { return self / 3.28084 } 7 | } 8 | let oneInch = 25.4.mm 9 | print("One inch is \(oneInch) meters") 10 | // prints "One inch is 0.0254 meters" 11 | let threeFeet = 3.ft 12 | print("Three feet is \(threeFeet) meters") 13 | // prints "Three feet is 0.914399970739201 meters" 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Swift is like Kotlin 3 | 4 | Page: http://nilhcem.github.io/swift-is-like-kotlin/ 5 | 6 | Programmatically inspired from [swift-is-like-go](https://github.com/jiyinyiyong/swift-is-like-go) and visually inspired from [swiftislikescala](https://github.com/leverich/swiftislikescala) 7 | 8 | ### License 9 | 10 | MIT 11 | 12 | ### Develop 13 | 14 | ```bash 15 | npm i # install dependencies to build tools 16 | ./make.coffee dev # build html 17 | ``` 18 | 19 | HTML is generated from `cirru/index.cirru`. 20 | Read that file and you would know what's happening. 21 | -------------------------------------------------------------------------------- /code/subclass.kt: -------------------------------------------------------------------------------- 1 | open class NamedShape(val name: String) { 2 | var numberOfSides = 0 3 | 4 | open fun simpleDescription() = 5 | "A shape with $numberOfSides sides." 6 | } 7 | 8 | class Square(var sideLength: BigDecimal, name: String) : 9 | NamedShape(name) { 10 | init { 11 | numberOfSides = 4 12 | } 13 | 14 | fun area() = sideLength.pow(2) 15 | 16 | override fun simpleDescription() = 17 | "A square with sides of length $sideLength." 18 | } 19 | 20 | val test = Square(BigDecimal("5.2"), "square") 21 | test.area() 22 | test.simpleDescription() 23 | -------------------------------------------------------------------------------- /make.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | project = 'swift-is-like-kotlin' 3 | 4 | require 'shelljs/make' 5 | path = require 'path' 6 | mission = require 'mission' 7 | 8 | mission.time() 9 | 10 | cirru = (data) -> 11 | mission.cirruHtml 12 | file: 'index.cirru' 13 | from: 'cirru/' 14 | to: './' 15 | extname: '.html' 16 | data: data 17 | 18 | target.dev = -> 19 | cirru inDev: yes 20 | 21 | target.watch = -> 22 | station = mission.reload() 23 | 24 | mission.watch 25 | files: ['cirru/', 'code/'] 26 | trigger: (filepath, extname) -> 27 | cirru inDev: yes 28 | station.reload project 29 | 30 | target.patch = -> 31 | mission.bump 32 | file: 'package.json' 33 | options: 34 | at: 'patch' 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "swift-is-like-kotlin", 3 | "version": "0.0.2", 4 | "description": "Swift is like Kotlin ------", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "jiyinyiyong, nilhcem", 10 | "license": "MIT", 11 | "devDependencies": { 12 | "mission": "0.0.7", 13 | "shelljs": "^0.3.0" 14 | }, 15 | "dependencies": { 16 | "mission": "^0.0.7", 17 | "shelljs": "^0.3.0" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/Nilhcem/swift-is-like-kotlin.git" 22 | }, 23 | "keywords": [ 24 | "swift", 25 | "kotlin" 26 | ], 27 | "bugs": { 28 | "url": "https://github.com/Nilhcem/swift-is-like-kotlin/issues" 29 | }, 30 | "homepage": "https://github.com/Nilhcem/swift-is-like-kotlin" 31 | } 32 | -------------------------------------------------------------------------------- /code/subclass.swift: -------------------------------------------------------------------------------- 1 | class NamedShape { 2 | var numberOfSides: Int = 0 3 | let name: String 4 | 5 | init(name: String) { 6 | self.name = name 7 | } 8 | 9 | func simpleDescription() -> String { 10 | return "A shape with \(numberOfSides) sides." 11 | } 12 | } 13 | 14 | class Square: NamedShape { 15 | var sideLength: Double 16 | 17 | init(sideLength: Double, name: String) { 18 | self.sideLength = sideLength 19 | super.init(name: name) 20 | self.numberOfSides = 4 21 | } 22 | 23 | func area() -> Double { 24 | return sideLength * sideLength 25 | } 26 | 27 | override func simpleDescription() -> String { 28 | return "A square with sides of length " + 29 | sideLength + "." 30 | } 31 | } 32 | 33 | let test = Square(sideLength: 5.2, name: "square") 34 | test.area() 35 | test.simpleDescription() 36 | -------------------------------------------------------------------------------- /css/highlightjs-github.css: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | github.com style (c) Vasily Polovnyov 4 | 5 | */ 6 | 7 | .hljs { 8 | display: block; 9 | overflow-x: auto; 10 | padding: 0.5em; 11 | color: #333; 12 | } 13 | 14 | .hljs-comment, 15 | .hljs-quote { 16 | color: #998; 17 | font-style: italic; 18 | } 19 | 20 | .hljs-keyword, 21 | .hljs-selector-tag, 22 | .hljs-subst { 23 | color: #333; 24 | font-weight: bold; 25 | } 26 | 27 | .hljs-number, 28 | .hljs-literal, 29 | .hljs-variable, 30 | .hljs-template-variable, 31 | .hljs-tag .hljs-attr { 32 | color: #008080; 33 | } 34 | 35 | .hljs-string, 36 | .hljs-doctag { 37 | color: #d14; 38 | } 39 | 40 | .hljs-title, 41 | .hljs-section, 42 | .hljs-selector-id { 43 | color: #900; 44 | font-weight: bold; 45 | } 46 | 47 | .hljs-subst { 48 | font-weight: normal; 49 | } 50 | 51 | .hljs-type, 52 | .hljs-class .hljs-title { 53 | color: #458; 54 | font-weight: bold; 55 | } 56 | 57 | .hljs-tag, 58 | .hljs-name, 59 | .hljs-attribute { 60 | color: #000080; 61 | font-weight: normal; 62 | } 63 | 64 | .hljs-regexp, 65 | .hljs-link { 66 | color: #009926; 67 | } 68 | 69 | .hljs-symbol, 70 | .hljs-bullet { 71 | color: #990073; 72 | } 73 | 74 | .hljs-built_in, 75 | .hljs-builtin-name { 76 | color: #0086b3; 77 | } 78 | 79 | .hljs-meta { 80 | color: #999; 81 | font-weight: bold; 82 | } 83 | 84 | .hljs-deletion { 85 | background: #fdd; 86 | } 87 | 88 | .hljs-addition { 89 | background: #dfd; 90 | } 91 | 92 | .hljs-emphasis { 93 | font-style: italic; 94 | } 95 | 96 | .hljs-strong { 97 | font-weight: bold; 98 | } 99 | -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: "Helvetica Neue", sans-serif; 3 | margin: 0; 4 | } 5 | 6 | body * { 7 | box-sizing: border-box; 8 | } 9 | 10 | .section { 11 | background-color: #f4f4f4; 12 | padding: 4em 3em; 13 | } 14 | 15 | .section:nth-child(2n) { 16 | background-color: white; 17 | } 18 | 19 | .title { 20 | font-size: 2.7em; 21 | color: #888; 22 | font-weight: 100; 23 | letter-spacing: 0.2em; 24 | text-align: center; 25 | } 26 | 27 | .case {} 28 | 29 | .name { 30 | font-size: 1.8em; 31 | color: #444; 32 | font-weight: 300; 33 | text-align: center; 34 | margin: 60px; 35 | } 36 | 37 | .pair { 38 | display: flex; 39 | display: -webkit-flex; 40 | display: -ms-flexbox; 41 | justify-content: center; 42 | -webkit-justify-content: center; 43 | -ms-box-pack: center; 44 | -ms-box-align: center; 45 | } 46 | 47 | .card { 48 | flex: 1; 49 | -webkit-flex: 1; 50 | -ms-flex: 1; 51 | max-width: 590px; 52 | margin: 0 10px; 53 | } 54 | 55 | .lang { 56 | font-size: 1.3em; 57 | color: #666; 58 | padding-bottom: 0; 59 | font-weight: 200; 60 | letter-spacing: 0.07em; 61 | } 62 | 63 | .code { 64 | font-size: 1.15em; 65 | background-color: white; 66 | margin: 0.4em 0 0 0; 67 | padding: 0.4em; 68 | line-height: 1.3em; 69 | } 70 | .section:nth-child(2n) .code { 71 | background-color: #f4f4f4; 72 | } 73 | 74 | #fork-me { 75 | position: absolute; 76 | right: 0; 77 | } 78 | 79 | #note { 80 | font-size: 1.5em; 81 | color: #fff; 82 | text-align: center; 83 | padding: 0.6em; 84 | background: #414141; 85 | font-weight: 300; 86 | letter-spacing: 0.05em; 87 | } 88 | -------------------------------------------------------------------------------- /cirru/index.cirru: -------------------------------------------------------------------------------- 1 | doctype 2 | 3 | html 4 | head 5 | title "Swift is like Kotlin" 6 | meta (:charset utf-8) 7 | link (:rel stylesheet) (:href css/style.css) 8 | link (:rel stylesheet) (:href css/highlightjs-github.css) 9 | script (:src js/highlight.9.4.0.js) 10 | script "hljs.initHighlightingOnLoad();" 11 | 12 | body 13 | a (:target _blank) 14 | :href https://github.com/Nilhcem/swift-is-like-kotlin 15 | img#fork-me (:src http://nilhcem.github.io/swift-is-like-kotlin/fork-me.png) 16 | #note 17 | = "Swift is like Kotlin" 18 | 19 | .section 20 | .title BASICS 21 | .case (.name "Hello World") $ .pair 22 | .card (.lang Swift) $ pre.code $ code (@insert ../code/hello-world.swift) 23 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/hello-world.kt) 24 | .case (.name "Variables And Constants") $ .pair 25 | .card (.lang Swift) $ pre.code $ code (@insert ../code/variables-and-constants.swift) 26 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/variables-and-constants.kt) 27 | .case (.name "Explicit Types") $ .pair 28 | .card (.lang Swift) $ pre.code $ code (@insert ../code/explicit-types.swift) 29 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/explicit-types.kt) 30 | .case (.name "Type Coercion") $ .pair 31 | .card (.lang Swift) $ pre.code $ code (@insert ../code/type-coercion.swift) 32 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/type-coercion.kt) 33 | .case (.name "String Interpolation") $ .pair 34 | .card (.lang Swift) $ pre.code $ code (@insert ../code/string-interpolation.swift) 35 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/string-interpolation.kt) 36 | .case (.name "Range Operator") $ .pair 37 | .card (.lang Swift) $ pre.code $ code (@insert ../code/range-operator.swift) 38 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/range-operator.kt) 39 | .case (.name "Inclusive Range Operator") $ .pair 40 | .card (.lang Swift) $ pre.code $ code (@insert ../code/inclusive-range-operator.swift) 41 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/inclusive-range-operator.kt) 42 | 43 | .section 44 | .title COLLECTIONS 45 | .case (.name "Arrays") $ .pair 46 | .card (.lang Swift) $ pre.code $ code (@insert ../code/arrays.swift) 47 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/arrays.kt) 48 | .case (.name "Maps") $ .pair 49 | .card (.lang Swift) $ pre.code $ code (@insert ../code/maps.swift) 50 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/maps.kt) 51 | .case (.name "Empty Collections") $ .pair 52 | .card (.lang Swift) $ pre.code $ code (@insert ../code/empty-collections.swift) 53 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/empty-collections.kt) 54 | 55 | .section 56 | .title FUNCTIONS 57 | .case (.name "Functions") $ .pair 58 | .card (.lang Swift) $ pre.code $ code (@insert ../code/functions.swift) 59 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/functions.kt) 60 | .case (.name "Tuple Return") $ .pair 61 | .card (.lang Swift) $ pre.code $ code (@insert ../code/tuple-return.swift) 62 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/tuple-return.kt) 63 | .case (.name "Variable Number Of Arguments") $ .pair 64 | .card (.lang Swift) $ pre.code $ code (@insert ../code/variable-number-of-arguments.swift) 65 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/variable-number-of-arguments.kt) 66 | .case (.name "Function Type") $ .pair 67 | .card (.lang Swift) $ pre.code $ code (@insert ../code/function-type.swift) 68 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/function-type.kt) 69 | .case (.name "Map") $ .pair 70 | .card (.lang Swift) $ pre.code $ code (@insert ../code/map.swift) 71 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/map.kt) 72 | .case (.name "Sort") $ .pair 73 | .card (.lang Swift) $ pre.code $ code (@insert ../code/sort.swift) 74 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/sort.kt) 75 | .case (.name "Named Arguments") $ .pair 76 | .card (.lang Swift) $ pre.code $ code (@insert ../code/named-arguments.swift) 77 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/named-arguments.kt) 78 | 79 | .section 80 | .title CLASSES 81 | .case (.name "Declaration") $ .pair 82 | .card (.lang Swift) $ pre.code $ code (@insert ../code/declaration.swift) 83 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/declaration.kt) 84 | .case (.name "Usage") $ .pair 85 | .card (.lang Swift) $ pre.code $ code (@insert ../code/usage.swift) 86 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/usage.kt) 87 | .case (.name "Subclass") $ .pair 88 | .card (.lang Swift) $ pre.code $ code (@insert ../code/subclass.swift) 89 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/subclass.kt) 90 | .case (.name "Checking Type") $ .pair 91 | .card (.lang Swift) $ pre.code $ code (@insert ../code/checking-type.swift) 92 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/checking-type.kt) 93 | .case (.name "Pattern Matching") $ .pair 94 | .card (.lang Swift) $ pre.code $ code (@insert ../code/pattern-matching.swift) 95 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/pattern-matching.kt) 96 | .case (.name "Downcasting") $ .pair 97 | .card (.lang Swift) $ pre.code $ code (@insert ../code/downcasting.swift) 98 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/downcasting.kt) 99 | .case (.name "Protocol") $ .pair 100 | .card (.lang Swift) $ pre.code $ code (@insert ../code/protocol.swift) 101 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/protocol.kt) 102 | .case (.name "Extensions") $ .pair 103 | .card (.lang Swift) $ pre.code $ code (@insert ../code/extensions.swift) 104 | .card (.lang Kotlin) $ pre.code $ code (@insert ../code/extensions.kt) 105 | -------------------------------------------------------------------------------- /js/highlight.9.4.0.js: -------------------------------------------------------------------------------- 1 | /*! highlight.js v9.4.0 | BSD3 License | git.io/hljslicense */ 2 | !function(e){var n="object"==typeof window&&window||"object"==typeof self&&self;"undefined"!=typeof exports?e(exports):n&&(n.hljs=e({}),"function"==typeof define&&define.amd&&define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&/gm,"&").replace(//gm,">")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&&e.exec(n);return t&&0==t.index}function a(e){return/^(no-?highlight|plain|text)$/i.test(e)}function i(e){var n,t,r,i=e.className+" ";if(i+=e.parentNode?e.parentNode.className:"",t=/\blang(?:uage)?-([\w-]+)\b/i.exec(i))return w(t[1])?t[1]:"no-highlight";for(i=i.split(/\s+/),n=0,r=i.length;r>n;n++)if(w(i[n])||a(i[n]))return i[n]}function o(e,n){var t,r={};for(t in e)r[t]=e[t];if(n)for(t in n)r[t]=n[t];return r}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3==i.nodeType?a+=i.nodeValue.length:1==i.nodeType&&(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&&r.length?e[0].offset!=r[0].offset?e[0].offset"}function u(e){f+=""}function c(e){("start"==e.event?o:u)(e.node)}for(var s=0,f="",l=[];e.length||r.length;){var g=i();if(f+=n(a.substr(s,g[0].offset-s)),s=g[0].offset,g==e){l.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g==e&&g.length&&g[0].offset==s);l.reverse().forEach(o)}else"start"==g[0].event?l.push(g[0].node):l.pop(),c(g.splice(0,1)[0])}return f+n(a.substr(s))}function s(e){function n(e){return e&&e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var u={},c=function(n,t){e.cI&&(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");u[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?c("keyword",a.k):Object.keys(a.k).forEach(function(e){c(e,a.k[e])}),a.k=u}a.lR=t(a.l||/\w+/,!0),i&&(a.bK&&(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&&(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&&i.tE&&(a.tE+=(a.e?"|":"")+i.tE)),a.i&&(a.iR=t(a.i)),void 0===a.r&&(a.r=1),a.c||(a.c=[]);var s=[];a.c.forEach(function(e){e.v?e.v.forEach(function(n){s.push(o(e,n))}):s.push("self"==e?a:e)}),a.c=s,a.c.forEach(function(e){r(e,a)}),a.starts&&r(a.starts,i);var f=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=f.length?t(f.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){for(var t=0;t";return i+=e+'">',i+n+o}function h(){if(!k.k)return n(M);var e="",t=0;k.lR.lastIndex=0;for(var r=k.lR.exec(M);r;){e+=n(M.substr(t,r.index-t));var a=g(k,r);a?(B+=a[1],e+=p(a[0],n(r[0]))):e+=n(r[0]),t=k.lR.lastIndex,r=k.lR.exec(M)}return e+n(M.substr(t))}function d(){var e="string"==typeof k.sL;if(e&&!R[k.sL])return n(M);var t=e?f(k.sL,M,!0,y[k.sL]):l(M,k.sL.length?k.sL:void 0);return k.r>0&&(B+=t.r),e&&(y[k.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=void 0!==k.sL?d():h(),M=""}function v(e,n){L+=e.cN?p(e.cN,"",!0):"",k=Object.create(e,{parent:{value:k}})}function m(e,n){if(M+=e,void 0===n)return b(),0;var t=o(n,k);if(t)return t.skip?M+=n:(t.eB&&(M+=n),b(),t.rB||t.eB||(M=n)),v(t,n),t.rB?0:n.length;var r=u(k,n);if(r){var a=k;a.skip?M+=n:(a.rE||a.eE||(M+=n),b(),a.eE&&(M=n));do k.cN&&(L+=""),k.skip||(B+=k.r),k=k.parent;while(k!=r.parent);return r.starts&&v(r.starts,""),a.rE?0:n.length}if(c(n,k))throw new Error('Illegal lexeme "'+n+'" for mode "'+(k.cN||"")+'"');return M+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var x,k=i||N,y={},L="";for(x=k;x!=N;x=x.parent)x.cN&&(L=p(x.cN,"",!0)+L);var M="",B=0;try{for(var C,j,I=0;;){if(k.t.lastIndex=I,C=k.t.exec(t),!C)break;j=m(t.substr(I,C.index-I),C[0]),I=C.index+j}for(m(t.substr(I)),x=k;x.parent;x=x.parent)x.cN&&(L+="");return{r:B,value:L,language:e,top:k}}catch(O){if(-1!=O.message.indexOf("Illegal"))return{r:0,value:n(t)};throw O}}function l(e,t){t=t||E.languages||Object.keys(R);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r>a.r&&(a=t),t.r>r.r&&(a=r,r=t)}),a.language&&(r.second_best=a),r}function g(e){return E.tabReplace&&(e=e.replace(/^((<[^>]+>|\t)+)/gm,function(e,n){return n.replace(/\t/g,E.tabReplace)})),E.useBR&&(e=e.replace(/\n/g,"
")),e}function p(e,n,t){var r=n?x[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&&a.push(r),a.join(" ").trim()}function h(e){var n=i(e);if(!a(n)){var t;E.useBR?(t=document.createElementNS("http://www.w3.org/1999/xhtml","div"),t.innerHTML=e.innerHTML.replace(/\n/g,"").replace(//g,"\n")):t=e;var r=t.textContent,o=n?f(n,r,!0):l(r),s=u(t);if(s.length){var h=document.createElementNS("http://www.w3.org/1999/xhtml","div");h.innerHTML=o.value,o.value=c(s,u(h),r)}o.value=g(o.value),e.innerHTML=o.value,e.className=p(e.className,n,o.language),e.result={language:o.language,re:o.r},o.second_best&&(e.second_best={language:o.second_best.language,re:o.second_best.r})}}function d(e){E=o(E,e)}function b(){if(!b.called){b.called=!0;var e=document.querySelectorAll("pre code");Array.prototype.forEach.call(e,h)}}function v(){addEventListener("DOMContentLoaded",b,!1),addEventListener("load",b,!1)}function m(n,t){var r=R[n]=t(e);r.aliases&&r.aliases.forEach(function(e){x[e]=n})}function N(){return Object.keys(R)}function w(e){return e=(e||"").toLowerCase(),R[e]||R[x[e]]}var E={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0},R={},x={};return e.highlight=f,e.highlightAuto=l,e.fixMarkup=g,e.highlightBlock=h,e.configure=d,e.initHighlighting=b,e.initHighlightingOnLoad=v,e.registerLanguage=m,e.listLanguages=N,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|like)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("swift",function(e){var t={keyword:"__COLUMN__ __FILE__ __FUNCTION__ __LINE__ as as! as? associativity break case catch class continue convenience default defer deinit didSet do dynamic dynamicType else enum extension fallthrough false final for func get guard if import in indirect infix init inout internal is lazy left let mutating nil none nonmutating operator optional override postfix precedence prefix private protocol Protocol public repeat required rethrows return right self Self set static struct subscript super switch throw throws true try try! try? Type typealias unowned var weak where while willSet",literal:"true false nil",built_in:"abs advance alignof alignofValue anyGenerator assert assertionFailure bridgeFromObjectiveC bridgeFromObjectiveCUnconditional bridgeToObjectiveC bridgeToObjectiveCUnconditional c contains count countElements countLeadingZeros debugPrint debugPrintln distance dropFirst dropLast dump encodeBitsAsWords enumerate equal fatalError filter find getBridgedObjectiveCType getVaList indices insertionSort isBridgedToObjectiveC isBridgedVerbatimToObjectiveC isUniquelyReferenced isUniquelyReferencedNonObjC join lazy lexicographicalCompare map max maxElement min minElement numericCast overlaps partition posix precondition preconditionFailure print println quickSort readLine reduce reflect reinterpretCast reverse roundUpToAlignment sizeof sizeofValue sort split startsWith stride strideof strideofValue swap toString transcode underestimateCount unsafeAddressOf unsafeBitCast unsafeDowncast unsafeUnwrap unsafeReflect withExtendedLifetime withObjectAtPlusZero withUnsafePointer withUnsafePointerToObject withUnsafeMutablePointer withUnsafeMutablePointers withUnsafePointer withUnsafePointers withVaList zip"},i={cN:"type",b:"\\b[A-Z][\\w']*",r:0},n=e.C("/\\*","\\*/",{c:["self"]}),r={cN:"subst",b:/\\\(/,e:"\\)",k:t,c:[]},a={cN:"number",b:"\\b([\\d_]+(\\.[\\deE_]+)?|0x[a-fA-F0-9_]+(\\.[a-fA-F0-9p_]+)?|0b[01_]+|0o[0-7_]+)\\b",r:0},o=e.inherit(e.QSM,{c:[r,e.BE]});return r.c=[a],{k:t,c:[o,e.CLCM,n,i,a,{cN:"function",bK:"func",e:"{",eE:!0,c:[e.inherit(e.TM,{b:/[A-Za-z$_][0-9A-Za-z$_]*/}),{b://},{cN:"params",b:/\(/,e:/\)/,endsParent:!0,k:t,c:["self",a,o,e.CBCM,{b:":"}],i:/["']/}],i:/\[|%/},{cN:"class",bK:"struct protocol class extension enum",k:t,e:"\\{",eE:!0,c:[e.inherit(e.TM,{b:/[A-Za-z$_][0-9A-Za-z$_]*/})]},{cN:"meta",b:"(@warn_unused_result|@exported|@lazy|@noescape|@NSCopying|@NSManaged|@objc|@convention|@required|@noreturn|@IBAction|@IBDesignable|@IBInspectable|@IBOutlet|@infix|@prefix|@postfix|@autoclosure|@testable|@available|@nonobjc|@NSApplicationMain|@UIApplicationMain)"},{bK:"import",e:/$/,c:[e.CLCM,n]}]}});hljs.registerLanguage("kotlin",function(e){var t={keyword:"abstract as val var vararg get set class object open private protected public noinline crossinline dynamic final enum if else do while for when throw try catch finally import package is in fun override companion reified inline interface annotation data sealed internal infix operator out by constructor super trait volatile transient native default",built_in:"Byte Short Char Int Long Boolean Float Double Void Unit Nothing",literal:"true false null"},r={cN:"keyword",b:/\b(break|continue|return|this)\b/,starts:{c:[{cN:"symbol",b:/@\w+/}]}},n={cN:"symbol",b:e.UIR+"@"},i={cN:"subst",v:[{b:"\\$"+e.UIR},{b:"\\${",e:"}",c:[e.ASM,e.CNM]}]},a={cN:"string",v:[{b:'"""',e:'"""',c:[i]},{b:"'",e:"'",i:/\n/,c:[e.BE]},{b:'"',e:'"',i:/\n/,c:[e.BE,i]}]},c={cN:"meta",b:"@(?:file|property|field|get|set|receiver|param|setparam|delegate)\\s*:(?:\\s*"+e.UIR+")?"},s={cN:"meta",b:"@"+e.UIR,c:[{b:/\(/,e:/\)/,c:[e.inherit(a,{cN:"meta-string"})]}]};return{k:t,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,r,n,c,s,{cN:"function",bK:"fun",e:"[(]|$",rB:!0,eE:!0,k:t,i:/fun\s+(<.*>)?[^\s\(]+(\s+[^\s\(]+)\s*=/,r:5,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"type",b://,k:"reified",r:0},{cN:"params",b:/\(/,e:/\)/,endsParent:!0,k:t,r:0,c:[{b:/:/,e:/[=,\/]/,eW:!0,c:[{cN:"type",b:e.UIR},e.CLCM,e.CBCM],r:0},e.CLCM,e.CBCM,c,s,a,e.CNM]},e.CBCM]},{cN:"class",bK:"class interface trait",e:/[:\{(]|$/,eE:!0,i:"extends implements",c:[{bK:"public protected internal private constructor"},e.UTM,{cN:"type",b://,eB:!0,eE:!0,r:0},{cN:"type",b:/[,:]\s*/,e:/[<\(,]|$/,eB:!0,rE:!0},c,s]},a,{cN:"meta",b:"^#!/usr/bin/env",e:"$",i:"\n"},e.CNM]}}); --------------------------------------------------------------------------------