作为一名Java开发人员,支持领域的概念对我来说有点陌生.鉴于:
class Sample {
var counter = 0 // the initializer value is written directly to the backing field
set(value) {
if (value >= 0) field = value
}
}
Run Code Online (Sandbox Code Playgroud)
这个支持领域有什么用?Kotlin博士说:Kotlin的课程不能有字段.但是,有时在使用自定义访问器时需要有一个支持字段.为什么?在setter中使用属性名称本身的区别是什么.
class Sample {
var counter = 0
set(value) {
if (value >= 0) this.counter = value // or just counter = value?
}
}
Run Code Online (Sandbox Code Playgroud) 我正在获取mp3 url作为api调用的响应.我想播放那个音频,那我怎么能这样做呢?(ios swift)
这是我的回答
{
content = "En este primer programa se tratar\U00e1n asuntos tan importante como este y aquel sin descuidar un poco de todo lo dem\U00e1s";
file = "http://radio.spainmedia.es/wp-content/uploads/2015/12/ogilvy.mp3";
image = "http://radio.spainmedia.es/wp-content/uploads/2015/12/tapas.jpg";
number = 0001;
subtitle = Titulareando;
title = "Tapa 1";
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码::
@IBAction func btnplayaudio(sender: AnyObject) {
let urlstring = "http://radio.spainmedia.es/wp-content/uploads/2015/12/tailtoddle_lo4.mp3"
let url = NSURL(string: urlstring)
print("the url = \(url!)")
play(url!)
}
func play(url:NSURL) {
print("playing \(url)")
do {
self.player = try AVAudioPlayer(contentsOfURL: url)
player.prepareToPlay()
player.volume …
Run Code Online (Sandbox Code Playgroud) 我有大量的数据页面.我想在10秒内自动显示当前页面的下一页,现在我有2个链接用于下一页和后面.但我想自动显示它.如果页面计数到达最后一页,则它将显示第一页.
for ($counterstart=$startcounter ;
$counterstart<=count($device)-1;$counterstart++){
$entry = $device[$counterstart] ;
echo "page";
}
if ($startcounter ==$result ){
echo " Back ";
}else{
echo "Next";
}
Run Code Online (Sandbox Code Playgroud) 嗨,据我所知whatsapp
支持abid
和text
参数如下:
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
Run Code Online (Sandbox Code Playgroud)
但我想发送一个新号码的消息.例如,如果我的电话号码是+123456
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?abid=+123456"];
Run Code Online (Sandbox Code Playgroud)
这不起作用.
因为如果用户插入客户的whatsapp
号码,应用程序应弹出whatsapp
带有此号码的消息框.
我注意到在某些情况下我可以发送消息到联系人列表中未列出的号码.我想知道它是如何工作的.
我一直在看Kotlin官方教程.我遇到了一个名为Backing Fields的主题
它说,
Kotlin中的类不能有字段.但是,有时在使用自定义访问器时需要有一个支持字段.出于这些目的,Kotlin提供了一个自动支持字段,可以使用字段标识符访问该字段:
var counter = 0 // the initializer value is written directly to the backing field
set(value) {
if (value >= 0) field = value
}
Run Code Online (Sandbox Code Playgroud)
我从这个官方链接得到了上述内容
我的问题是,"字段"指向计数器变量吗?
有人可以为我提供一个支持领域的例子,还是用一个理解词来形容我?
我一直在尝试在Kotlin中使用扩展功能.
class ExtensionExample() {
var name: String? = null
fun Any?.toString() : String {
if (this == null) {
return "Value is null"
}
return "Value is not null"
}
}
Run Code Online (Sandbox Code Playgroud)
当我打印名称变量如下所示
println(ExtensionExample().name.toString())
Run Code Online (Sandbox Code Playgroud)
它应该打印出来
Value is null
Run Code Online (Sandbox Code Playgroud)
但它不像我预期的那样打印.它只打印null
.
有人可以解释一下吗?