Kotlin 與 Swift 語法對照:跨平台開發者 (2025年)

Kotlin 與 Swift 語法對照表(2025 年版) 在行動應用開發中, Kotlin 與 Swift 分別是 Android 與 iOS 的主流語言。雖然語法有些差異,但其實它們有很多相似之處。本文整理了常用的語法對照表,方便跨平台開發者快速上手。 1. 變數宣告 // Kotlin val name: String = "Alice" // 常數 var age: Int = 25 // 可變數 // Swift let name: String = "Alice" // 常數 var age: Int = 25 // 可變數 2. 條件判斷 // Kotlin if (age >= 18) { println("Adult") } else { println("Minor") } // Swift if age >= 18 { print("Adult") } else { print("Minor") } 3. 函式定義 // Kotlin fun greet(name: String): String { return "Hello, $name!" } // Swift func greet(_ name: String) -> String { return "Hello, \(name)!" } 4. 陣列與迴圈 // Kotlin val fruits = listOf("Apple", "Banana", "Cherry") for (fruit in fruits) { println(fruit) } // Swift let fruits = ["Apple", "Banana", "Cherry"] for fruit in fruits { print(f...

Geth 進入console時直接連接節點 Ethereum PrivateNet

在私鏈環境下,可以在進入節點的console模式同時

讓它跟某一個節點連線,只要設定參數即可
 (功能就像是進入console後輸入admin.addPeer())


之前有提到,假設我們有個 node 1,輸入如下指令進入console

geth --ipcdisable --rpc --rpcport 8104 --datadir "./privatechain/01" --networkid 123 --rpcapi="db,eth,net,web3,debug" --port=30310 console

用了port 30310與rpcport 8104 此時,透過第二個Termeral,輸入指令

geth --ipcdisable --rpc --rpcport 8102 --datadir "./privatechain/02" --networkid 123 --rpcapi="db,eth,net,web3,personal" --port=30312 --bootnodes "enode://be7c34c1ddbb9d95ac9b4d96db47e133a39be4a785d1dc3ce4e382cf082c5a4a78c7397a0662836c11c5acaac6c5b7d7fc9064bebb1e218aabe0f424db8d84b5@127.0.0.1:30310" console

其中port與rpcport要跟node 1不同,networkid則要相同
補上參數--bootnodes [node 1的enode]

node 1畫面(點擊看大圖): 
nd1.png

node 2畫面(點擊看大圖): 
nd1.png

備註:

1.ip的地方如果是[::]要改成127.0.0.1,否則系統似乎無法辨識

2.node 2 的port在顯示節點資訊時與連線狀態下明顯不同,意義不明

留言

這個網誌中的熱門文章

【Ubuntu】Terminal 複製貼上的方法 Copy & Paste

【Ubuntu】關閉預設畫面自動鎖定

[Java] HashMap資料結構簡介與用法