本文将介绍Swift中的inout参数的详细情况,特别是关于swiftinit方法的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于androidst
本文将介绍Swift 中的 inout 参数的详细情况,特别是关于swift init方法的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于android studio AIDL的使用(四)in,inout,out、cannot convert value of type 'String!' to expected argument type 'inout String'、d 语言之 inout 关键字、f2py 是否仅支持类型为 Intent(inout) 的函数?的知识。
本文目录一览:- Swift 中的 inout 参数(swift init方法)
- android studio AIDL的使用(四)in,inout,out
- cannot convert value of type 'String!' to expected argument type 'inout String'
- d 语言之 inout 关键字
- f2py 是否仅支持类型为 Intent(inout) 的函数?
Swift 中的 inout 参数(swift init方法)
如何解决Swift 中的 inout 参数
在尝试研究 ionut 参数时,我遇到了一个例子 code。
此代码引发错误:
“执行被中断,原因:信号SIGABRT。进程已经离开中断点,使用“线程返回-x”返回表达式求值前的状态。
但是,当尝试对实际项目进行 debag 时,po char 1。
var num1: Int = 1
var char1 = "a"
func changeNumber(num: Int) {
var num = num
num = 2
print(num) // 2
print(num1) // 1
}
changeNumber(num: num1)
func changeChar(char: inout String) {
char = "b"
print(char) // b
print(char1) // b
}
changeChar(char: &char1)
请解释为什么会出现此错误以及如何解决?
解决方法
错误应该在堆栈跟踪的顶部:
Simultaneous accesses to 0x109fac098,but modification requires exclusive access.
当您将 char1
作为 inout
参数传递给 changeChar
时,在该函数返回之前以任何其他方式访问 char1
都是内存冲突。
有关完整的详细信息,请参阅 SE-176 Enforce Exclusive Access to Memory,它在 Swift 4 中添加了此限制。
android studio AIDL的使用(四)in,inout,out
1.in:子进程值不能传回主进程
代码:
Log.d(TAG, "onClick: "+String.valueOf(message.isSendSuccess()));
其实他在remoteService设置了isSendSuccess为true,但打印结果是false。即它在remoteService设置为true,但是没有改变在MainActivity中的值
2.inout:两个进程可以交互
设置为inout
编译的时候不通过,会爆红,添加代码:
//inout的时候添加
public void readFromParcel(Parcel parcel){
content=parcel.readString();
isSendSuccess=parcel.readByte()==1;
}
然后运行,连接,记得等待5秒,然后打印的值为true,即remoteService改变值,影响了MainActivity
3.out:主进程不能向子进程发数据
out与in反过来
代码直接修改为out即可
在remoteService中的打印结果为空
cannot convert value of type 'String!' to expected argument type 'inout String'
var area_big:String!var area_small:String!
var types = ""
var firstIn = true
provinces.forEach { (province) in
let count = province.children.count
for i in 0..<count{
if i == 0 && province.children[i].checked {
if area_big == nil {
area_big = province.children[i].attributes["name"]
}else{
area_big += "#" + province.children[i].attributes["name"]!
}
}
}
}
如果是按照上面那样写 ,会报如题错误。改为如下就可以了
var area_big:String! var area_small:String! var types = "" var firstIn = true provinces.forEach { (province) in let count = province.children.count for i in 0..<count{ if i == 0 && province.children[i].checked { if area_big == nil { area_big = province.children[i].attributes["name"] }else{ area_big = area_big + "#" + province.children[i].attributes["name"]! } } } }
d 语言之 inout 关键字
参考自 d 程序设计语言 --- 我的博客 http://my.oschina.net/u/218155/blog?fromerr=SwOkb7Sw fllow me
inout 主要是用来推测是否是 imutability,const, 空类型的.
我们可以 inout (char)[] 代表既可以是 immutable (char)[] 也可以是 char [] 有点类似泛型。但是他只作用于 immutable
import std.stdio;
void main() {
string parenthesized1(string phrase) {
return ''('' ~ phrase ~ '')'';
}
writeln(parenthesized1("hiparenthesized"));
char[] m;
m ~= "hi";
//writeln(parenthesized(m));
char[] parenthesized2(char[] phrase) {
return ''('' ~ phrase ~ '')'';
}
writeln(parenthesized2(m));
const(char)[] parenthesized3(const(char)[] phrase) {
return ''('' ~ phrase ~ '')'';
}
writeln(parenthesized3(m));
inout(char)[] parenthesized(inout(char)[] phrase) {
return ''('' ~ phrase ~ '')'';
}
writeln(typeof("hiparenthesized").stringof);
writeln(parenthesized("hiparenthesized"));
writeln(typeof(m).stringof);
writeln(parenthesized(m));
writeln(typeid(typeof("hiparenthesized")));
string c1(string s){
return ''#''~s;
}
char[] c2(char[] s){
return ''#''~s;
}
inout (char)[] c3(inout(char)[] s){
return ''#''~s;
}
}
f2py 是否仅支持类型为 Intent(inout) 的函数?
如何解决f2py 是否仅支持类型为 Intent(inout) 的函数?
我将纯 F90 宇宙学库连接到 python 代码,以便通过在 F90 中编写互连函数来绘制一些图,该函数使用了上述库中的几个函数,例如,
使用 cosmology_functions
其中 cosmology_functions 是一个模块,其中包含一些带有下划线的函数,例如“init_cosmology”。我成功编译了这个互连,但是当我尝试在我的 python 脚本中导入它时,我发现了这个问题:
导入错误:$PATH$/Interconnection.cpython-38-x86_64-linux-gnu.so:未定义符号:__cosmology_functions_MOD_init_cosmology
奇怪的是,在 ''init_cosmology'' 之前调用了几个函数并且我没有收到错误报告。所以我怀疑是不是函数本身造成的错误是用f2py。这个函数的输入输出很简单:
子程序init_cosmology(cosm)
类型(宇宙学),意图(输入):: 宇宙
在此函数内部向cosm添加参数的地方,使输入维度和输出维度彼此不同。这是 f2py 的固有问题吗?还是我猜错了?
编译器为 GNU fortran 9.3.0,python 版本为 3.8.5。
非常感谢。
关于Swift 中的 inout 参数和swift init方法的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于android studio AIDL的使用(四)in,inout,out、cannot convert value of type 'String!' to expected argument type 'inout String'、d 语言之 inout 关键字、f2py 是否仅支持类型为 Intent(inout) 的函数?等相关知识的信息别忘了在本站进行查找喔。
本文标签: