草庐IT

Kotlin-script

全部标签

swift - 可以扩展 Kotlin 类以符合接口(interface)(就像 Swift 类一样)吗?

在Swift中,我可以创建一个协议(protocol)来做类似的事情protocolFoobarConvertible{varfoobar:String{get}}然后用符合标准的实现扩展系统中的任何类extensionString:FoobarConvertible{varfoobar:String{get{return"foobar"}}}在Kotlin中,我认为接口(interface)类似于协议(protocol)(?),我可以这样声明一个interfaceFoobarConvertible{valfoobar:String}但是我从文档(这似乎是一个简洁的练习)中看不出的是我

android - 在 Kotlin 中无法 "findViewById"。收到错误 "Type inference failed"

当我尝试通过id查找RecycleView时出现以下错误。Error:-Typeinferencefailed:NotenoughinformationtoinferparameterT代码:classFirstRecycleViewExample:AppCompatActivity(){valdata=arrayListOf()overridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)setContentView(R.layout.first_recycleview)valrec

android - 在 Kotlin 中无法 "findViewById"。收到错误 "Type inference failed"

当我尝试通过id查找RecycleView时出现以下错误。Error:-Typeinferencefailed:NotenoughinformationtoinferparameterT代码:classFirstRecycleViewExample:AppCompatActivity(){valdata=arrayListOf()overridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)setContentView(R.layout.first_recycleview)valrec

swift - 在 swift package generate-xcodeproj 之后维护 Xcode Run Script Phase

我的Xcode项目中有一个运行脚本阶段。通过swiftpackageupdate使用SPM更新我的依赖项后,我必须使用swiftpackagegenerate-xcodeproj更新我的项目。在不使用ruby​​gem、podspec或其他第3部分工具的情况下,我如何维护该构建阶段?我能以某种方式将运行脚本阶段添加到xcconfig文件吗? 最佳答案 目前使用SwiftPM,xcode项目文件是从模板生成的,并且其上的任何扩展都被认为是短暂的-xcode项目文件的重新创建只查看Package.swift中的内容,而不是任何现有项目。

android - 从 Swift 访问 Kotlin 标准库

在我的KotlinMultiplatform项目中,我试图从Swift访问kotlin-stdlib中定义的Kotlin类型。TL;DR:StdLib类型/方法似乎不会导致header定义,我想要一个不涉及编写大量样板代码我的场景我在Kotlin中定义了一个接口(interface)...interfaceMyKotlinInterface{funrun():Sequence}...并在Swift中实现了这个接口(interface)...classMySwiftClass:MyKotlinInterface{funcrun()->KotlinSequence{//returnsequ

swift - Kotlin 是否有像 Swift 那样的接口(interface)扩展类

在Swift中,我们可以使用如下接口(interface)扩展一个类extensionMyExtend{publicvartype:String{return""}}extensionMyOrigin:MyExtend{publicvartype:ListItemDataType{return"Origin"}}我们在Kotlin中有这种能力吗?(例如扩展接口(interface)) 最佳答案 是的,Kotlin确实有Extensions—类似于Swift。swift:classC{funcfoo(i:String){print("

android - 如何获取每个 Kotlin 的当前索引

如何在foreach循环中获取索引?我想为每第二次迭代打印一次数字例如for(valueincollection){if(iteration_no%2){//dosomething}}在java中,我们有传统的for循环for(inti=0;i如何获取i? 最佳答案 除了@Audi提供的解决方案,还有forEachIndexed:collection.forEachIndexed{index,element->//...} 关于android-如何获取每个Kotlin的当前索引,我们在S

android - 如何获取每个 Kotlin 的当前索引

如何在foreach循环中获取索引?我想为每第二次迭代打印一次数字例如for(valueincollection){if(iteration_no%2){//dosomething}}在java中,我们有传统的for循环for(inti=0;i如何获取i? 最佳答案 除了@Audi提供的解决方案,还有forEachIndexed:collection.forEachIndexed{index,element->//...} 关于android-如何获取每个Kotlin的当前索引,我们在S

android - Kotlin 错误 : Could not find org. jetbrains.kotlin :kotlin-stdlib-jre7:1. 0.7

我将Kotlin插件安装到我的应用程序中(v.v1.1.1-release-Studio2.2-1),然后选择“在项目中配置Kotlin”我选择了1.0.7的编译器和运行时版本。Kotlin更新了我的Gradle文件。现在,当我尝试构建时,我得到:Error:Aproblemoccurredconfiguringproject':app'.Couldnotresolvealldependenciesforconfiguration':app:_debugApkCopy'.Couldnotfindorg.jetbrains.kotlin:kotlin-stdlib-jre7:1.0.7.

android - Kotlin 错误 : Could not find org. jetbrains.kotlin :kotlin-stdlib-jre7:1. 0.7

我将Kotlin插件安装到我的应用程序中(v.v1.1.1-release-Studio2.2-1),然后选择“在项目中配置Kotlin”我选择了1.0.7的编译器和运行时版本。Kotlin更新了我的Gradle文件。现在,当我尝试构建时,我得到:Error:Aproblemoccurredconfiguringproject':app'.Couldnotresolvealldependenciesforconfiguration':app:_debugApkCopy'.Couldnotfindorg.jetbrains.kotlin:kotlin-stdlib-jre7:1.0.7.