https://kotlinlang.org
Join Slack
I want to take first character from firstName and lastName. Also firstName and lastName may be null....
v

Vivek Modi

about 4 years ago
I want to take first character from firstName and lastName. Also firstName and lastName may be null. I want to ask is there better way to approach this? firstName :
Vivek
or
Dr. Vivek
lastName
Modi
private fun getInitials(firstName: String?, lastName: String?): String {
    var initials = ""
    if (firstName != null && firstName.isNotEmpty()) {
        initials += firstName.take(1)
    }
    if (lastName != null && lastName.isNotEmpty()) {
        initials += lastName.take(1)
    }
    return initials
}
For example
Vivek Modi
output
VM
but when i enter
Dr. Vivek Modi
i want
VM
v
g
+2
  • 4
  • 10
  • 362
for MockK, i'm getting `MockKException: no answer found for: MyClass(#1).sendMessage(okhttp3.Request...
k

Kulwinder Singh

over 5 years ago
for MockK, i'm getting
MockKException: no answer found for: MyClass(#1).sendMessage(okhttp3.RequestBody$2@4ed4bd33)
, actually RequestBody's properties are same just instance is different. that's why it did not matches parameters but if i add
any()
instead of requestbody it works. is there anything else i can use instead of
any()
here ?
every {	myClass.sendMessage(MockRequest.createTestBody(value="text")) } answers { something }

....

class SomeObject(myClass:MyClass){
	fun doSomething(text: String): Flowable<Result<Boolean>> {
        val request = MockRequest.createTestBody(text)
		myClass.sendMessage(request)
	}
}
....
i have checked documentation of mockk but didn't found anything, that's why asked here:
k
c
  • 2
  • 26
  • 362
When might I expect SKIE to be updated to support the latest version of Kotlin (2.0.20)? I upgraded...
t

Trey

about 1 year ago
When might I expect SKIE to be updated to support the latest version of Kotlin (2.0.20)? I upgraded to the latest version of macos and now Xcode 15.4 isn't supported. When using Xcode 16 or 16.1, cinterop issues cause a failure with sys/cdefs.h. I tried updating my Kotlin version, but SKIE says it isn't supported. Any way I can SKIE continue even if it isn't officially supported? I want to continue using SKIE, not disable it. My issue: https://youtrack.jetbrains.com/issue/KT-70566/LLVM-11-clang-with-Xcode-16-headers-sys-cdefs.h-file-not-found
⬆️ 1
t
t
+2
  • 4
  • 11
  • 361
I think I am getting crazy soon about brew vs Mac OS, everytime update cocoapods or ruby something b...
j

Joel Denke

almost 2 years ago
I think I am getting crazy soon about brew vs Mac OS, everytime update cocoapods or ruby something breaks. I always end up in this:
Execution failed for task ':core:data:podInstallSyntheticIos'.
> Executing of 'env pod install' failed with code 1 and message: 
  
  
  
  /opt/homebrew/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/specification.rb:1484:in `rescue in block in activate_dependencies': Could not find 'minitest' (>= 5.1) among 182 total gem(s) (Gem::MissingSpecError)
  Checked in 'GEM_PATH=/opt/homebrew/Cellar/fastlane/2.219.0_2/libexec:/opt/homebrew/Cellar/cocoapods/1.15.2/libexec' at: /opt/homebrew/Cellar/cocoapods/1.15.2/libexec/specifications/activesupport-7.1.3.gemspec, execute `gem env` for more information
Tried re-install ruby, cocoapods, follow some odd configs in ~/.zshrc file etc. But nothing works. What should I do to successfully being able to use Ruby 3.3.0+ and Cocoapods on MacOS so I can build my iOS app properly? And yes minitest is installed but I think something is missing to specify GEM_PATH or something.
✅ 1
kodee happy 1
j
d
  • 2
  • 14
  • 361
How would I use kotlinx.coroutines in combination with a blocking framework like lwjgl? I can't find...
m

martmists

almost 4 years ago
How would I use kotlinx.coroutines in combination with a blocking framework like lwjgl? I can't find anything in the docs about cases like this
m
g
+2
  • 4
  • 52
  • 361
[SOLVED] Hello, I am getting some errors when running a Ktor server that uses the Location feature, ...
a

Alexandre Brown

over 4 years ago
[SOLVED] Hello, I am getting some errors when running a Ktor server that uses the Location feature, the ktor app was compiled into a GraalVM native image and upon running it I get the following :
Exception in thread "DefaultDispatcher-worker-2" kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Unresolved class: class applications.web.routes.roadclassification.MyLocation
import <http://io.ktor.locations.post|io.ktor.locations.post>

...
fun Routing.myFun() {
	route("/my-route") {
		post<MyLocation> {
			call.respondText { "hello" }
		}
	}
}
import io.ktor.locations.Location

@Location("/mylocation")
class MyLocation
The app works when not running the native image (regular jar) or when running the native image without using the Location feature. Thanks
a
r
  • 2
  • 13
  • 361
I'm using spring webflux `WebFilter` with kotlin coroutines, currently the only way I can run `suspe...
t

tvtan

almost 5 years ago
I'm using spring webflux
WebFilter
with kotlin coroutines, currently the only way I can run
suspend function
in
filter
function is using
runBlocking
. Is there a better way for calling a suspend function in that case?
t
d
  • 2
  • 4
  • 361
Hello, what is the best practice for error handling for Kotlin errors thrown in KMP shared code to i...
j

Jason

10 months ago
Hello, what is the best practice for error handling for Kotlin errors thrown in KMP shared code to iOS? Right now, basic errors in shared code don't show full stack trace or inner errors. Do I have to handle all KMP errors on Kotlin side then return custom Error result type which I have explicitly defined so iOS can read the error from there? Looks like bridging of Kotlin Error/Exception to Swift is not really well thought out right now. I was hoping to define custom Errors in Kotlin and just throw them, having Swift code catch it and be able to determine exact error/ root cause from that but looks like i can't do that.
j
e
  • 2
  • 3
  • 360
would I be able to use multiplatform for tizen and webos?
m

Marc Javier

over 3 years ago
would I be able to use multiplatform for tizen and webos?
m
d
+2
  • 4
  • 6
  • 360
Injecting dependencies in ViewModel with inheritance using Hilt without constructor parameters Hell...
s

sk eat

over 1 year ago
Injecting dependencies in ViewModel with inheritance using Hilt without constructor parameters Hello, I need some advice on a problem I'm facing. I have a feature A with sub-features AA and AB. I want to separate the logic of AA and AB by creating a
BaseViewModel
and then have
AAViewModel
and
ABViewModel
inherit from it. We are using Hilt in our project to inject dependencies into the
BaseViewModel
. Here is an example of what I am trying to achieve:
kotlin

@HiltViewModel
open class BaseViewModel @Inject constructor(
    private val sampleUseCase: SampleUseCase,
    private val anotherUseCase: AnotherUseCase
) : ViewModel() {
    // BaseViewModel logic
}
The problem arises when I try to implement the class that inherits from `BaseViewModel`:
kotlin

@HiltViewModel
class AAViewModel @Inject constructor(
    private val secondSampleUseCase: SecondSampleUseCase
) : BaseViewModel(
    // error! Too many parameters to pass
) {
    // AAViewModel logic
}
When inheriting from
BaseViewModel
, I need to pass many member variables through the constructor, which is cumbersome and error-prone. I want to eliminate the constructor parameters. How can I achieve this using Hilt?
not kotlin but kotlin colored 2
🧵 1
s
r
+3
  • 5
  • 5
  • 360
Previous189190191Next

kotlinlang

A modern programming language that makes developers happier.

Powered by