Swift Macbook在编译应用程序时崩溃
在编译我的项目时,编译器在这个类上卡住了,在尝试构建大约5分钟后,我收到一条消息,告诉我系统内存不足,需要关闭一些应用程序才能继续。这段代码中有什么东西会导致编译器崩溃吗 我正在使用XCode9,因为我的整个电脑都崩溃了,这可能是XCode的错误吗Swift Macbook在编译应用程序时崩溃,swift,xcode,Swift,Xcode,在编译我的项目时,编译器在这个类上卡住了,在尝试构建大约5分钟后,我收到一条消息,告诉我系统内存不足,需要关闭一些应用程序才能继续。这段代码中有什么东西会导致编译器崩溃吗 我正在使用XCode9,因为我的整个电脑都崩溃了,这可能是XCode的错误吗 import UIKit class ConferenceNumberViewController: UITableViewController, UINavigationControllerDelegate { let sections
import UIKit
class ConferenceNumberViewController: UITableViewController, UINavigationControllerDelegate {
let sections = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
let countries = CallIn.Data.allCountries
var indexedCountries =
[
"A": [String](),
"B": [String](),
"C": [String](),
"D": [String](),
"E": [String](),
"F": [String](),
"G": [String](),
"H": [String](),
"I": [String](),
"J": [String](),
"K": [String](),
"L": [String](),
"M": [String](),
"N": [String](),
"O": [String](),
"P": [String](),
"Q": [String](),
"R": [String](),
"S": [String](),
"T": [String](),
"U": [String](),
"V": [String](),
"W": [String](),
"X": [String](),
"Y": [String](),
"Z": [String]()
]
var countryNumberIndex: Int = 0
var indexedConferenceNumbers = CallIn.Data.indexedConferenceNumbers
var selectedConferenceNumber: CallIn.ConferenceNumber!
override func viewDidLoad() {
super.viewDidLoad()
countryAndConference = true
// Do any additional setup after loading the view.
//hide back button according to design
navigationItem.setHidesBackButton(true, animated: false)
for section in sections {
for country in countries {
let searchCharacter: Character = section.characters.first!
let countryCheck: Character = country.characters.first!
let compare = countryCheck == searchCharacter
if compare {
indexedCountries[section]!.append(country)
}
}
}
// indexedConferenceNumbers = indexedConferenceNumbers.sort(sortFunc) // moved the sorting to the Data class
}
/*func sortFunc(num1: CallIn.ConferenceNumber, num2: CallIn.ConferenceNumber) -> Bool {
return num1.country == num2.country ? (num1.typeOfNumber > num2.typeOfNumber) : (num1.country < num2.country)
}*/ // moved the sorting to the Data class
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// custom section view
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let header: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView //recast your view as a UITableViewHeaderFooterView
header.contentView.backgroundColor = Design.Colours.lightBlue // make the background light grey
if (accessibilityON){
header.textLabel!.font = UIFont(descriptor: UIFontDescriptor.regularDescriptor(UIFontTextStyle.body.rawValue), size: 0)
} else { header.textLabel!.font = UIFont.systemFont(ofSize: 13)}
// header.textLabel!.textColor = Design.Colours.subtextDarkGrey //make the text dark grey
// header.textLabel!.font = UIFont.systemFontOfSize(13) // set size of text
//header.alpha = 0.5 //make the header transparent
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CountryCell", for: indexPath)
let country = cell.viewWithTag(511) as! UILabel
let number = cell.viewWithTag(512) as! UILabel
let type = cell.viewWithTag(513) as! UILabel
// we have to calculate the index (jump) because the conference numbers list is single array (there are no sections)
var jump = 0
for index in 0...(indexPath as NSIndexPath).section {
(index == (indexPath as NSIndexPath).section) ? (jump = jump + (indexPath as NSIndexPath).row) : (jump = jump + indexedCountries[sections[index]]!.count)
}
country.text = indexedConferenceNumbers[jump].country
number.text = indexedConferenceNumbers[jump].conferenceNumber
type.text = indexedConferenceNumbers[jump].typeOfNumber
return cell
}
override func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return indexedCountries[sections[section]]!.count
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if (countriesPerSection("\(sections[section])").count == 0) {
return nil
}
return sections[section] as String
}
//index on the right side of the screen
override func sectionIndexTitles(for tableView: UITableView) -> ([String]!){
return self.sections
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if (countriesPerSection("\(sections[section])").count == 0) {
return 0.1
}
return 30.0
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let indexPath = self.tableView.indexPathForSelectedRow {
tableView.deselectRow(at: indexPath, animated: true)
let selectedCell = tableView.cellForRow(at: indexPath) as UITableViewCell!
let country = selectedCell?.contentView.viewWithTag(511) as! UILabel
let number = selectedCell?.contentView.viewWithTag(512) as! UILabel
let type = selectedCell?.contentView.viewWithTag(513) as! UILabel
// Set the number to be passed to SettingDetailsViewController after the unwind segue.
selectedConferenceNumber = CallIn.ConferenceNumber(country: country.text!, conferenceNumber: number.text!, typeOfNumber: type.text!, isoCode: "")
}
}
private func countriesPerSection(_ section: String) -> [String] {
var matches = [String]()
for country in indexedCountries["\(section)"]! {
matches.append(country)
}
return matches
}
private func conferenceNumbersPerCountry(_ country: String) -> Array<CallIn.ConferenceNumber> {
var matches = Array<CallIn.ConferenceNumber>()
for numbers in indexedConferenceNumbers {
if numbers.country == country {
let conferenceNumber = CallIn.ConferenceNumber(country: numbers.country, conferenceNumber: numbers.conferenceNumber, typeOfNumber: numbers.typeOfNumber, isoCode: numbers.isoCode)
matches.append(conferenceNumber)
}
}
return matches
}
@IBAction private func goBack(_ sender: UIBarButtonItem) {
self.navigationController!.popViewController(animated: true)
}
}
导入UIKit
类会议NumberViewController:UITableViewController、UINavigationControllerDelegate{
设节=[“A”、“B”、“C”、“D”、“E”、“F”、“G”、“H”、“I”、“J”、“K”、“L”、“M”、“N”、“O”、“P”、“Q”、“R”、“S”、“T”、“U”、“V”、“W”、“X”、“Y”、“Z”]
let countries=CallIn.Data.allCountries
var指数国家=
[
“A”:[字符串](),
“B”:[字符串](),
“C”:[字符串](),
“D”:[字符串](),
“E”:[字符串](),
“F”:[字符串](),
“G”:[字符串](),
“H”:[字符串](),
“I”:[字符串](),
“J”:[字符串](),
“K”:[字符串](),
“L”:[字符串](),
“M”:[字符串](),
“N”:[字符串](),
“O”:[字符串](),
“P”:[字符串](),
“Q”:[字符串](),
“R”:[字符串](),
“S”:[字符串](),
“T”:[字符串](),
“U”:[字符串](),
“V”:[字符串](),
“W”:[字符串](),
“X”:[字符串](),
“Y”:[字符串](),
“Z”:[字符串]()
]
变量countryNumberIndex:Int=0
var indexedConferenceNumbers=CallIn.Data.indexedConferenceNumbers
var selectedConferenceNumber:CallIn.ConferenceNumber!
重写func viewDidLoad(){
super.viewDidLoad()
countryAndConference=true
//加载视图后执行任何其他设置。
//根据设计隐藏后退按钮
navigationItem.setHidesBackButton(true,动画:false)
一节接一节{
国家中的国家{
让searchCharacter:Character=section.characters.first!
让countryCheck:Character=country.characters.first!
让compare=countryCheck==searchCharacter
如果比较{
indexedCountries[部分]!.追加(国家)
}
}
}
//IndexedConferenceNumber=IndexedConferenceNumber.sort(sortFunc)//将排序移动到数据类
}
/*func sortFunc(num1:CallIn.ConferenceNumber,num2:CallIn.ConferenceNumber)->Bool{
返回num1.country==num2.country?(num1.typeOfNumber>num2.typeOfNumber):(num1.countryUITableViewCell{
let cell=tableView.dequeueReusableCell(标识符为“CountryCell”,表示:indexath)
让country=cell.viewWithTag(511)作为!UILabel
设number=cell.viewWithTag(512)为!UILabel
让type=cell.viewWithTag(513)作为!UILabel
//我们必须计算索引(跳转),因为会议号码列表是单个数组(没有节)
var跳跃=0
对于0中的索引…(indexPath作为NSIndexPath)。节{
(index==(indexPath作为NSIndexPath.section)?(jump=jump+(indexPath作为NSIndexPath.row):(jump=jump+indexedCountries[sections[index]]!.count)
}
country.text=indexedConferenceNumber[jump].country
number.text=indexedConferenceNumber[jump].conferenceNumber
type.text=indexedConferenceNumber[跳转].typeOfNumber
返回单元
}
重写func numberOfSections(在tableView:UITableView中)->Int{
返回节数
}
重写func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回indexedCountries[节[节]!.计数
}
重写func tableView(tableView:UITableView,titleForHeaderInSection:Int)->String{
if(countriesPerSection(“\(sections[section])”)。count==0){
归零
}
以字符串形式返回节[section]
}
//索引位于屏幕右侧
重写func sectionIndexTitles(对于tableView:UITableView)->([String]!){
返回自动分区
}
重写func tableView(tableView:UITableView,heightForHeaderInSection:Int)->CGFloat{
if(countriesPerSection(“\(sections[section])”)。count==0){
返回0.1
}
返回30.0
}
覆盖功能准备(对于segue:UIStoryboardSegue,发送方:有吗?){
如果让indexPath=self.tableView.indexPathForSelectedRow{
取消选择行(at:indexPath,动画:true)
让selectedCell=tableView.cellForRow(at:indexPath)作为UITableViewCell!
让country=selectedCell?.contentView.viewWithTag(511)作为!UILabel
设number=selectedCell?.contentView.viewWithTag(512)为!UI
var indexedCountries: [String, [String]] =
var indexedCountries = [String, [String]]()
for letter in sections {
indexedCountries[letter] = [String]()
}
let sections: [String] = [ "A", ... ]