iOS - 计时器选择器线程

时间:2017-06-22 02:44:44

标签: ios swift multithreading timer selector

我有一个Swift代码,

const schoolData = [
  { school : 'Middle School', year : '2017', date : '6/12/17', location : 
'Class',},
  { school : 'High School', year : '2017', date : '2/24/17', location : 
'Gym',},

];

// declare this in render method
const headers = Object.keys(schoolData[0]).map(header => 
    <TableHeaderColumn>{header}</TableHeaderColumn>);
    
// put it in your react component
<TableHeader displaySelectAll={false} adjustForCheckbox={false}>
  <TableRow>
    { headers }
  </TableRow>
</TableHeader>

// for TableRows
const rows = (row) => Object.keys(row).map(r => 
    <TableRowColumn>{row[r]}</TableRowColumn>);

<TableRow>
  {rows(row)}
</TableRow>

此代码从主线程运行,比如var timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.updateAction), userInfo: nil, repeats: true) 。我想知道这个选择器viewDidLoad()是否保证在主线程中运行。换句话说,如果我在updateAction()中有UI操作,我是否应该在主线程上明确地包装代码。

1 个答案:

答案 0 :(得分:2)

您的Timer将始终在主线程上运行,因此您始终可以在updateAction()更新用户界面。