This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Person(val age:Int, val name:String) { | |
val greet | |
get() = "年齢は${age}です" | |
fun testPrint() { | |
println("testPrint ${age}" ) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isContinue:Boolean = true | |
val list = arrayOf("hello", "good", "text", "hello2", "text2") | |
val result = list.asSequence().takeWhile{isContinue}.reduce {s1, s2-> | |
if(s1.length == 4 && s2.length == 4) { | |
isContinue = false | |
return@reduce s1+s2 | |
} | |
s2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val amari = 8.rem(3) | |
println(amari) | |
// Output | |
// 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val num = 'a'.toValue() | |
println(num) | |
// Output | |
// 42 | |
private fun Char.toValue() : Int{ | |
// 仕様: https://www.icao.int/publications/Documents/9303_p3_cons_en.pdf の 20ページの最後から21ページの最初 | |
val num = this.toInt() - '0'.toInt() | |
if(num < 10) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File().outputStream().use { out -> | |
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, out) | |
out.flush() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import GoogleMaps | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
// https://developers.google.com/maps/documentation/ios-sdk/get-api-key#add_key | |
GMSServices.provideAPIKey("YOUR_API_KEY") | |
return true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class User(val name : String, val latLng: LatLng) | |
data class LatLng(val lat: Int, val lng: Int) | |
fun deleteDuplicates() { | |
// create data | |
val results = (1..10).map {User("$it", LatLng(it % 4, it%4))} | |
results.forEach { | |
println(it) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum FromNagative: Int { | |
case a = -1 | |
case b | |
case c | |
} | |
print(FromNagative.a.rawValue) // -1 | |
print(FromNagative.b.rawValue) // 0 | |
print(FromNagative.c.rawValue) // 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
let url = URL(string: "https://jsonplaceholder.typicode.com/posts/1")! | |
func fetch(callback:( (String) -> Void)? = nil) { | |
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in | |
guard error == nil else { | |
callback?(error?.localizedDescription ?? "エラーです") |