终结者在基本块的中间找到

时间:2015-07-03 07:32:42

标签: xcode swift clang llvm llvm-clang

一切顺利,直到我的项目无法编译。我在两个文件中看到了这些内容。

Terminator found in the middle of a basic block!
label %50
LLVM ERROR: Broken function found, compilation aborted!


Terminator found in the middle of a basic block!
label %71
LLVM ERROR: Broken function found, compilation aborted!

编译器给出的错误

Command /Applications/Xcode-beta 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

我尝试解决它,但没有成功。 较旧版本的文件编译。 问题出在文件中,但终止符是什么?

问题出在哪里?

修改

这是一些代码,类很大

LandscapeViewController

 import UIKit

        class LandscapeViewController: UIViewController,UIScrollViewDelegate {

            // MARK: Properties
            @IBOutlet weak var scrollView: UIScrollView!
            @IBOutlet weak var pageControl: UIPageControl!

            var search: Search!
            private var firstTime = true
            private var downloadTasks = [NSURLSessionDownloadTask]()

            @IBAction func pageChange(sender: UIPageControl){
                UIView.animateWithDuration(0.3, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
                    self.scrollView.contentOffset = CGPoint(x: self.scrollView.bounds.size.width * CGFloat(sender.currentPage), y: 0)
                    }, completion: nil )
            }



            // MARK: Buttons
            private func tileButtons(searchResults: [SearchResult]){
                var columnsPerPage = 5
                var rowsPerPage = 3
                var itemWidth: CGFloat = 96
                var itemHeight: CGFloat = 88
                var marginX: CGFloat = 0
                var marginY: CGFloat = 20
                let buttonWidth: CGFloat = 82
                let buttonHeight: CGFloat = 82

                let scrollViewWidth = scrollView.bounds.size.width

                switch scrollViewWidth{
                case 568:
                    columnsPerPage = 6
                    itemWidth = 94
                    marginX = 2
                case 667:
                    columnsPerPage = 7
                    itemWidth = 95
                    itemHeight = 98
                    marginX = 1
                    marginY = 29
                case 736:
                    columnsPerPage = 8
                    rowsPerPage = 4
                    itemWidth = 92
                default:
                    break
                }

                let paddingHorz = (itemWidth - buttonWidth)/2
                let paddingVert = (itemHeight - buttonHeight)/2

                var row = 0
                var column = 0
                var x = marginX

                for (index,searchResult) in searchResults.enumerate(){

                    let button = UIButton(type: .Custom)
                    button.setBackgroundImage(UIImage(named: "LandscapeButton"), forState: .Normal)

                    downloadImageForSearchResult(searchResult, andPlaceOnButton: button)

                    button.tag = 2000 + index
                    button.addTarget(self, action: Selector("buttonPressed:"), forControlEvents: .TouchUpInside)

                    button.backgroundColor = UIColor.whiteColor()

                    button.frame = CGRect(x: x + paddingHorz, y: marginY + CGFloat(row)*itemHeight + paddingVert, width: buttonWidth, height: buttonHeight)
                    scrollView.addSubview(button)
                    ++row
                    if row == rowsPerPage{
                        row = 0
                        ++column
                        x += itemWidth

                        if column == columnsPerPage{
                            column = 0
                            x += marginX * 2
                        }

                    }


                }

                let buttonsPerPage = columnsPerPage * rowsPerPage
                let numPages = 1 + (searchResults.count - 1) / buttonsPerPage
                pageControl.numberOfPages = numPages
                pageControl.currentPage = 0

                scrollView.contentSize = CGSize(width: CGFloat(numPages) * scrollViewWidth, height: scrollView.bounds.size.height)


            }

            private func downloadImageForSearchResult(searchResult: SearchResult,andPlaceOnButton button: UIButton){
                if let url = NSURL(string: searchResult.artworkURL60){
                    let session = NSURLSession.sharedSession()
                    let downloadTask = session.downloadTaskWithURL(url,completionHandler: { [weak button] url, response, error in
                        if error == nil && url != nil{
                            if let data = NSData(contentsOfURL: url!){
                                if let image = UIImage(data: data){
                                    let resizedImage = image.resizedImageWithBounds(CGSize(width: 60, height: 60))
                                    dispatch_async(dispatch_get_main_queue()){
                                        if let button = button{
                                            button.setImage(resizedImage, forState: .Normal)
                                        }
                                    }
                                }
                            }
                        }
                        })
                    downloadTasks.append(downloadTask!)
                    downloadTask?.resume()
                }
            }

            override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
                if segue.identifier == "ShowDetail"{
                    switch search.state{
                    case .Results(let list):
                        let destinationViewController = segue.destinationViewController as! DetailViewController
                        let searchResult = list[sender!.tag - 2000]
                        destinationViewController.searchResult = searchResult
                    default:
                        break
                    }
                }
            }

            func buttonPressed(sender: UIButton){
                performSegueWithIdentifier("ShowDetail", sender: sender)
            }

            // MARK: UIScrollViewDelegate

            func scrollViewDidScroll(scrollView: UIScrollView) {
                let width = scrollView.bounds.size.width
                let currentPage = Int((scrollView.contentOffset.x + width/2) / width)
                pageControl.currentPage = currentPage
            }

            // MARK: Lifecycle

            override func viewDidLoad() {
                super.viewDidLoad()
                pageControl.numberOfPages = 0

                scrollView.backgroundColor = UIColor(patternImage: UIImage(named: "LandscapeBackground")!)


                view.removeConstraints(view.constraints)
                view.translatesAutoresizingMaskIntoConstraints = true

                pageControl.removeConstraints(pageControl.constraints)
                pageControl.translatesAutoresizingMaskIntoConstraints = true

                scrollView.removeConstraints(scrollView.constraints)
                scrollView.translatesAutoresizingMaskIntoConstraints = true

                // Do any additional setup after loading the view.
            }

            override func viewWillLayoutSubviews() {
                super.viewWillLayoutSubviews()


                scrollView.frame = view.bounds

                pageControl.frame = CGRect(x: 0, y: view.frame.size.height - pageControl.frame.size.height, width: view.frame.size.width, height: pageControl.frame.size.height)

                if firstTime{
                    firstTime = false
                    switch search.state{
                    case .NotSearchedYet:
                        break
                    case .Loading:
                        showSpinner()
                    case .NoResults:
                        showNothingFoundLabel()
                    case.Results(let list):
                        tileButtons(list)
                    }
                }

            }

            private func showNothingFoundLabel() {
                let label = UILabel(frame: CGRect.zeroRect)
                label.text = "Nothing Found"

                label.backgroundColor = UIColor.clearColor()
                label.textColor = UIColor.whiteColor()

                label.sizeToFit()

                var rect = label.frame
                rect.size.width = ceil(rect.size.width/2) * 2
                rect.size.height = ceil(rect.size.height/2) * 2
                label.frame = rect

                label.center = CGPoint(x: CGRectGetMidX(scrollView.bounds), y: CGRectGetMidY(scrollView.bounds))

                view.addSubview(label)
            }

            private func showSpinner(){
                let spinner = UIActivityIndicatorView(activityIndicatorStyle: .WhiteLarge)
                spinner.center = CGPoint(x: CGRectGetMidX(scrollView.bounds) + 0.5, y: CGRectGetMidY(scrollView.bounds) + 0.5)

                spinner.tag = 1000
                view.addSubview(spinner)
                spinner.startAnimating()
            }

            func searchResultsRecived(){
                hideSpinner()

                switch search.state {
                case .NotSearchedYet, .Loading:
                    break
                case .NoResults:
                    showNothingFoundLabel()
                case .Results(let list):
                    tileButtons(list)
                }

            }

            private func hideSpinner(){
                view.viewWithTag(1000)?.removeFromSuperview()
            }

            override func didReceiveMemoryWarning() {
                super.didReceiveMemoryWarning()
                // Dispose of any resources that can be recreated.
            }


            deinit{
                print("deinit \(self)")

                for task in downloadTasks{
                    task.cancel()
                }
            }

            /*
            // MARK: - Navigation

            // In a storyboard-based application, you will often want to do a little preparation before navigation
            override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            // Get the new view controller using segue.destinationViewController.
            // Pass the selected object to the new view controller.
            }
            */

        }

SearchViewController

导入UIKit

            class SearchViewController: UIViewController,UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate {


            private struct TableViewCellIdentifier {
                static let searchResultCell = "SearchResultCell"
                static let nothingFoundCell = "NothingFoundCell"
                static let loadingCell = "LoadingCell"
            }

            // MARK: LandscapeViewController
            override func willTransitionToTraitCollection(newCollection: UITraitCollection, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
                super.willTransitionToTraitCollection(newCollection, withTransitionCoordinator: coordinator)

                switch newCollection.verticalSizeClass{
                case .Compact:
                    showLandscapeViewWithCoordinator(coordinator)
                case .Regular,.Unspecified:
                    hideLandscapeViewWithCoordinator(coordinator)

                }
            }

            private func showLandscapeViewWithCoordinator(coordinator: UIViewControllerTransitionCoordinator){
                precondition(landscapeViewController == nil)

                landscapeViewController = storyboard?.instantiateViewControllerWithIdentifier("LandscapeViewController") as? LandscapeViewController


                if let controller = landscapeViewController{
                    controller.search = search

                    controller.view.frame = view.frame
                    controller.view.alpha = 0


                    view.addSubview(controller.view)
                    addChildViewController(controller)

                    coordinator.animateAlongsideTransition({ _ in
                        if self.presentedViewController != nil{
                            self.dismissViewControllerAnimated(true, completion: nil)
                        }
                        self.searchBar.resignFirstResponder()
                        controller.view.alpha = 1
                        }, completion: { _ in
                            controller.didMoveToParentViewController(self)
                    })


                }


            }

            private func hideLandscapeViewWithCoordinator(coordinator: UIViewControllerTransitionCoordinator){
                if let controller = landscapeViewController{
                    controller.willMoveToParentViewController(nil)

                    coordinator.animateAlongsideTransition({ _ in
                        controller.view.alpha = 0
                        }, completion: { _ in
                            if self.presentedViewController != nil {
                                self.dismissViewControllerAnimated(true, completion: nil)
                            }
                            controller.view.removeFromSuperview()
                            controller.removeFromParentViewController()
                            self.landscapeViewController = nil
                    })

                }
            }



            private func showNetworkError(){
                let alert = UIAlertController(title: "Whoops...", message: "There was an error reading from the iTunes Store. Please try again.", preferredStyle: .Alert)

                let action = UIAlertAction(title: "OK", style: .Default, handler: nil)
                alert.addAction(action)

                presentViewController(alert, animated: true, completion: nil)

            }



            // MARK: Detail ViewController
            override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
                if segue.identifier == "ShowDetail" {
                    switch search.state{
                    case . Results(let list):
                        let indexPath = sender as! NSIndexPath
                        let searchResult = list[indexPath.row]
                        let detailViewController = segue.destinationViewController as! DetailViewController
                        detailViewController.searchResult = searchResult
                    default:
                        break
                    }
                }
            }


            // MARK: Properties
            @IBOutlet weak var searchBar: UISearchBar!
            @IBOutlet weak var tableView: UITableView!
            @IBOutlet weak var segmentedControl: UISegmentedControl!


            let search = Search()
            private var landscapeViewController: LandscapeViewController?

            // MARK: Methodes

            @IBAction func segmentedControl(sender: UISegmentedControl) {
                performSearch()
            }


            override func viewDidLoad() {
                super.viewDidLoad()
                tableView.contentInset = UIEdgeInsets(top: 108, left: 0, bottom: 0, right: 0)
                tableView.rowHeight = 80
                searchBar.becomeFirstResponder()
                configureNib(nibName: TableViewCellIdentifier.searchResultCell)
                configureNib(nibName: TableViewCellIdentifier.nothingFoundCell)
                configureNib(nibName: TableViewCellIdentifier.loadingCell)

            }

            private func configureNib(nibName nibName: String){
                let cellNib = UINib(nibName: nibName, bundle: nil)
                tableView.registerNib(cellNib, forCellReuseIdentifier: nibName)
            }


            // MARK: UISearchBarDelegate

            func searchBarSearchButtonClicked(searchBar: UISearchBar){
                performSearch()
            }

            private func performSearch() {
                if let category = Search.Category(rawValue: segmentedControl.selectedSegmentIndex){

                    search.performSearchForText(searchBar.text!, category: category){
                        success in
                        if !success{
                            self.showNetworkError()
                        }
                        if let controller = self.landscapeViewController{
                            controller.searchResultsRecived()
                        }

                        self.tableView.reloadData()
                    }

                    tableView.reloadData()
                    searchBar.resignFirstResponder()
                }
            }

            func positionForBar(bar: UIBarPositioning) -> UIBarPosition {
                return .TopAttached
            }


            // MARK:  TableView

            // MARK: - UITableViewDataSource

            func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                switch search.state{
                case .NotSearchedYet:
                    return 0
                case .Loading,.NoResults:
                    return 1
                case .Results(let list):
                    return list.count
                }
            }

            func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

                switch search.state{
                case .NotSearchedYet:
                    fatalError("Should never get here")
                case .Loading:
                    let cell = tableView.dequeueReusableCellWithIdentifier(TableViewCellIdentifier.loadingCell, forIndexPath: indexPath)
                    let spinner = cell.viewWithTag(100) as! UIActivityIndicatorView
                    spinner.startAnimating()

                    return cell

                case .NoResults:
                    return tableView.dequeueReusableCellWithIdentifier(TableViewCellIdentifier.nothingFoundCell, forIndexPath: indexPath)
                case .Results(let list):
                    let cell = tableView.dequeueReusableCellWithIdentifier(TableViewCellIdentifier.searchResultCell, forIndexPath: indexPath) as! SearchResultCell

                    let searchResult = list[indexPath.row]

                    cell.configureForSearchResult(searchResult)

                    return cell

                }
            }

            // MARK: UITableViewDelegate

            func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
                tableView.deselectRowAtIndexPath(indexPath, animated: true)
                performSegueWithIdentifier("ShowDetail", sender: indexPath)
            }

            func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
                switch search.state{
                case .NotSearchedYet,.NoResults,.Loading:
                    return nil
                case .Results:
                    return indexPath
                }
            }
            }

2 个答案:

答案 0 :(得分:2)

这是Swift编译器中的一个错误,您希望向Apple提交雷达以报告此情况。除此之外,你无能为力。

答案 1 :(得分:1)

我有这个错误,因为我有一个枚举的开关,其中包含一个包含数组有效负载的情况(不要问我为什么,我不知道)。

我认为enum是searchView中的搜索状态:SearchViewController的cellForRowAtIndexPath:方法和LandscapeViewController的prepareForSegue:方法(.Result案例包含列表)。

在我的情况下,将有效负载更改为设置而不是数组。 (作为一个工作区,直到它被修复)