Comparison memo for those who touch Kotlin (Android) from Swift (iOS) 1

A memorandum when people who came with Swift touch Kotlin Pick up places that are likely to stumble due to differences in concept

Basically used files

** drawable **, ** layout **, ** values ** under res ** kotlin ** under java (not test)

** drawable **: assets in ios, but can also save settings like css ** layout **: storyboard in iOS ** values **: A place where properties in ios are saved together in a struct etc. You can see it by looking at the color code, in-app text, etc. ** kotlin **: Contains the viewController file in Activity-ios

Layout

** Story Board ** in ** Xcode ** ** activity.xml ** in Android Studio **

Parented by ConstraintLayout, LinerLayout, and TableLayout (layout base) I will fill in the parts and make a layout.

When you want to place it in the middle

iOS

obj.frame.size.width / 2
obj.center.x(y)
//Center Vertical and Horizontal for storyboards

Android

app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"

parent is the parent element. Constraints the right side of the specified element to the right side of the parent element and the left side to the left side. If this is set to "@ id / part id", it can be set for the specified element. Due to the ** equal ** constraints on the left and right, the left and right force relationships of the parts are equal and placed in the middle.

app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="10dp"

If you add the third line like this, the power relationship will collapse and margin10dp will be on the right. Shift 10dp to the left.

Library management

iOS podfile(cocoapods) Android Gradle Installation (pod install in ios) Click the elephant mark (Sync Project with Cradle Files) in the execution menu

Screen transition

iOS performsegue, navigationController, etc. Android Screen movement Transition with ** startActivity ** using ** Intent instance ** Return finish() Since startActivity creates a new activity instance, Close (return) the screen with finish () unless there is a special reason

(Of course there are others, but at the moment we have implemented only the minimum required Only this is introduced)

Things on iOS but not on Android

segment control Since android does not have this, is it an override of RadioButton? Need to substitute with a button

import Since it can be used on iOS without importing UI parts, I'm unknowingly creating an instance, On Android, I'll install them one by one.

For example, in the case of Button, if you press enter when completion appears, import will be automatically entered. Otherwise it will be imported with option + Enter

java-> Kotlin automatic conversion

If you are accustomed to replacement, I think you can use Kotlin for java articles as well. Those who do not may find it useful. When I paste the java code into the editor, I'm asked if I want to convert it to Kotlin Convenient because there are few articles on Kotlin

Kotlin hates null

In Swift, it is declared with "?", But In Kotlin, add lateinit in addition to that

when Switch in iOS There is no when in iOS, so why not! Note that it may be when(int) { 1 -> println("int is 1") 2 -> println("int is 2") } Can be used like a Switch statement

in conclusion

What did you think? If you are used to Swift to some extent, if you can understand the layout part I think it can go smoothly to some extent. I'm glad if you can use it as a reference. If you find any mistakes, please point them out and we will correct them immediately.

Recommended Posts

Comparison memo for those who touch Kotlin (Android) from Swift (iOS) 1
Memo for migration from java to kotlin
[Swift] An illustration for those who say "Delegate is an agent."
Shortcut comparison for those migrating from Eclipse to IntelliJ IDEA (Windows)