是否有一个函数可以在Swift 2.1中返回变量/常量的推断类型?在下面的例子中,我想知道什么类型的" x"变量:
var x = false
答案 0 :(得分:1)
您可以使用TableLayout table = (TableLayout) getView().findViewById(R.id.youtTableLayout);
if(<your image size needs two cells>) {
TableRow row = (TableRow) LayoutInflater.from(getActivity().getApplicationContext())
.inflate(R.layout.two_cell_table_row, null);
}
else if(<your image size needs one cell) {
TableRow row = (TableRow) LayoutInflater.from(getActivity().getApplicationContext())
.inflate(R.layout.one_cell_table_row, null);
}
...
...
// add more conditions and respective layouts as you need.
...
...
ImageView myImgView = (ImageView) row.findViewById(R.id.txtCrdSectionHeader);
// set the image for your image view here.
table.addView(row);
table.requestLayout();
后缀:
.dynamicType
如果您想在运行时知道并使用该类型,可以将var x = false
print(x.dynamicType) // "Bool.Type"
的值存储在x
类型的变量中,并通过{{1}推断出类型Any
变量上的case。
switch