kotlin

oc项目中使用swift

旧街凉风 提交于 2020-12-24 07:31:34
一、为什么写这篇文章 我们整个移动开发团队都在从老的语言向新的语言过度,Android团队所有项目都在使用Kotlin开发了,但是iOS团队还在使用OC开发项目。团队负责人也已经发话了,iOS端从下个新项目开始都要使用swift开发了,对于基本没怎么使用过swift的同学来说,马上用新语言开发项目还是有一定难度、有一定风险的。从OC和swift混编开始,从OC向swift逐渐熟悉过度,是最佳选择,积累的经验,降低了难度,也降低了风险! 二、Swift目前现状 苹果在WWDC2014正式发布Swift,目的是用于替代OC语言。在之后的时间里经历了标准库变动,语法的增减,特性变动,几乎每一年 Swift 都会迎来比较大的改动,甚至 API 都发生了变化,让很多第一批吃螃蟹的开发者苦不堪言,戏称《Swift 从入门到重学》。如今已是2020年了,经过 6 年多的不断迭代更新,WWDC2019苹果发布了Swift5.0,苹果终于宣布了Swift的稳定。这标志着Swift这门语言已经趋于稳定,语法已经不会再大变,已经有越来越多的个人和公司在使用Swift,现在也到了重拾Swift的时候了。 三、本篇文章主要内容 1、在OC工程中配置swift需要的基本环境 2、oc和swift页面相互跳转,oc和swift属性相互调用,oc和swift方法相互调用

How to create a simple countdown timer in Kotlin?

ⅰ亾dé卋堺 提交于 2020-12-24 06:50:00
问题 I know how to create a simple countdown timer in Java. But I'd like to create this one in Kotlin. package android.os; new CountDownTimer(20000, 1000) { public void onTick(long millisUntilFinished) { mTextField.setText("seconds remaining: " + millisUntilFinished / 1000); } public void onFinish() { mTextField.setText("Time's finished!"); } }.start(); How can I do it using Kotlin? 回答1: You can use Kotlin objects: val timer = object: CountDownTimer(20000, 1000) { override fun onTick

How to create a simple countdown timer in Kotlin?

柔情痞子 提交于 2020-12-24 06:41:48
问题 I know how to create a simple countdown timer in Java. But I'd like to create this one in Kotlin. package android.os; new CountDownTimer(20000, 1000) { public void onTick(long millisUntilFinished) { mTextField.setText("seconds remaining: " + millisUntilFinished / 1000); } public void onFinish() { mTextField.setText("Time's finished!"); } }.start(); How can I do it using Kotlin? 回答1: You can use Kotlin objects: val timer = object: CountDownTimer(20000, 1000) { override fun onTick

How to create a simple countdown timer in Kotlin?

狂风中的少年 提交于 2020-12-24 06:41:29
问题 I know how to create a simple countdown timer in Java. But I'd like to create this one in Kotlin. package android.os; new CountDownTimer(20000, 1000) { public void onTick(long millisUntilFinished) { mTextField.setText("seconds remaining: " + millisUntilFinished / 1000); } public void onFinish() { mTextField.setText("Time's finished!"); } }.start(); How can I do it using Kotlin? 回答1: You can use Kotlin objects: val timer = object: CountDownTimer(20000, 1000) { override fun onTick

Android 实现圆角布局

 ̄綄美尐妖づ 提交于 2020-12-24 06:11:56
和尚我最近在处理图片的圆角,不止是四个角全是圆角,还包括单左侧/单右侧/对角线方向的圆角。因为自己太菜只能寻求网上的大神,发现一个自定义圆角布局,这样可以变相的解决我的需求,还可以实现更多的圆角效果,不仅是图片,还包括其他布局。 和尚我作为伸手党,非常感谢大神的分享,参考原文 RoundAngleFrameLayout。 这个布局实现方式很简单,大神只提供了默认的四个圆角,这里我添加了一些方法可以动态的设置圆角的位置与弧度,并说明一下和尚我遇到的小问题。和尚我根据大神的总结自定义了一个 MyRoundLayout GitHub 布局样式。 Tips: 在设置完角度之后,要添加 invalidate() 刷新 UI,才可以进行动态设置; 自定义的布局样式继承的 FrameLayout,所以设置在需要进行圆角的控件外即可,并不影响其内部控件的样式; 既然 MyRoundLayout 继承的是 FrameLayout,则应遵循 FrameLayout 的特点,内部不能直接设置控件的权重,可在内部添加一层 Layout 布局,在进行权重 weight 的处理; 在使用 MyRoundLayout 时,因为设置的是外层的圆角,所以不建议使用 padding 的属性,若要设置边距,建议使用外边距 margin,若使用 padding 不当,会发生效果图中第一行第二个的样式,没有直接效果;

No matching client found for package name “…” with different buildvariant

こ雲淡風輕ζ 提交于 2020-12-23 08:56:46
问题 I want o implement push notification. I added to project level: dependencies { classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.google.gms:google-services:3.0.0' } and to app level:(at the bottom of the file) .... compile 'com.squareup.okhttp3:okhttp:3.3.0' } apply plugin: 'com.google.gms.google-services' Then I added google-services.json file to project in app level But, when I syncro gradle, it launch the error: No matching client found for package name "...." In gradle I

No matching client found for package name “…” with different buildvariant

泄露秘密 提交于 2020-12-23 08:55:03
问题 I want o implement push notification. I added to project level: dependencies { classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.google.gms:google-services:3.0.0' } and to app level:(at the bottom of the file) .... compile 'com.squareup.okhttp3:okhttp:3.3.0' } apply plugin: 'com.google.gms.google-services' Then I added google-services.json file to project in app level But, when I syncro gradle, it launch the error: No matching client found for package name "...." In gradle I

Android Two Way DataBinding Problem of Ternary Operator Must be Constant

痞子三分冷 提交于 2020-12-23 08:22:32
问题 My EditText is like this: <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:text="@={viewModel.isAddCase? ``: `` + viewModel.currentStudent.age}" //problem here android:inputType="number" /> I want the EditText not to show anything (empty String) based on the isAddCase variable, which is a MutableLiveData<Boolean> initilized when the ViewModel class object is created (inside the init{} block). This is the error I got: The expression '(

Android Two Way DataBinding Problem of Ternary Operator Must be Constant

这一生的挚爱 提交于 2020-12-23 08:20:52
问题 My EditText is like this: <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:text="@={viewModel.isAddCase? ``: `` + viewModel.currentStudent.age}" //problem here android:inputType="number" /> I want the EditText not to show anything (empty String) based on the isAddCase variable, which is a MutableLiveData<Boolean> initilized when the ViewModel class object is created (inside the init{} block). This is the error I got: The expression '(

RxJava2的错误处理方案

不打扰是莪最后的温柔 提交于 2020-12-19 14:30:54
最近使用retrofit2 + rxKotlin2写接口访问,想尽量平铺代码,于是就想到当借口返回的状态码为「不成功」时(比如:code != 200),就连同网络错误一起,统一在onError方法中处理。想法总是好的,但是实际中却遇到onError无法捕获异常,造成应用崩溃的问题,终于在这个周末,我梳理清楚了RxJava的错误处理机制。 每一个后端接口基本都会有一个自定义的返回码,我们常常依据返回码来判断接口是否访问成功,是否成功返回我们想要的数据,当初作为一只菜鸟,我是这样来写的: fun login(account: String, pwd: String) { showProgress("登陆中")//展示菊花 service.login(account,pwd) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ if (it.code == 20000 && it.data != null) { //登陆成功! //跳转到主页 } else { //登陆失败! //弹出提示 //dismissProgress()关闭菊花 } }, { dismissProgress() //登陆失败! //弹出提示 //dismissProgress()关闭菊花 })