xcode 7.3.1 上的分段错误 11

Segmentation fault 11 on xcode 7.3.1

Archive 进程 with Xcode 7.3.1 (7D1014)

中出现奇怪错误
0  swift                    0x000000010d05766b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x000000010d056956 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x000000010d057ccf SignalHandler(int) + 287
3  libsystem_platform.dylib 0x00007fff91a3f52a _sigtramp + 26
4  libsystem_platform.dylib 0x000000010e1c5000 _sigtramp + 2088262384
5  swift                    0x000000010b08fd11 swift::SILPassManager::runModulePass(swift::SILModuleTransform*) + 1025
6  swift                    0x000000010b09053e swift::SILPassManager::runOneIteration() + 686
7  swift                    0x000000010b09660e swift::runSILOptimizationPasses(swift::SILModule&) + 462
8  swift                    0x000000010adaa579 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 13193
9  swift                    0x000000010ada668d frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2781
10 swift                    0x000000010ada20ac main + 1932
11 libdyld.dylib            0x00007fff8ff745ad start + 1



1.  While running SILModuleTransform "Closure Specialization".
Command failed due to signal: Segmentation fault: 11

出现错误的文件如下tabBarController.swift

这有助于我进行以下操作:如果用户按下选项卡栏按钮,则滚动视图会转到顶部。

import UIKit

class tapBarController: UITabBarController, UITabBarControllerDelegate {

    /// Determines whether the scrolling capability's enabled.
    var scrollEnabled: Bool = true

    private var previousIndex = 0

    override func viewDidLoad() {
        super.viewDidLoad()

        delegate = self
    }

    /*
     Always call "super" if you're overriding this method in your subclass.
     */
    func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {

        guard scrollEnabled else {
            return
        }

        guard let index = viewControllers?.indexOf(viewController) else {
            return
        }

        if index == previousIndex {
            var scrollViews = [UIScrollView]()

            dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), { [weak self] () in

                self?.iterateThroughSubviews(self?.view) { (scrollView) in
                    scrollViews.append(scrollView)
                }

                guard let scrollView = scrollViews.first else {
                    return
                }

                dispatch_async(dispatch_get_main_queue(), {
                    scrollView.setContentOffset(CGPointZero, animated: true)
                })
                })
        }

        previousIndex = index
    }

    /*
     Iterates through the view hierarchy in an attempt to locate a UIScrollView with "scrollsToTop" enabled.
     Since the functionality relies on "scrollsToTop", it plugs easily into existing architectures - you can
     control the behaviour by modifying "scrollsToTop" on your UIScrollViews.
     */
    private func iterateThroughSubviews(parentView: UIView?, onRecognition: (UIScrollView) -> Void) {
        guard let view = parentView else {
            return
        }

        for subview in view.subviews {
            if let scrollView = subview as? UIScrollView where scrollView.scrollsToTop == true {
                onRecognition(scrollView)
            }

            iterateThroughSubviews(subview, onRecognition: onRecognition)
        }
    }
}

如果我评论孔文件,那么我没有错误。我也无法从代码中弄清楚错误是什么(直到 2 天前它一直在工作并且已存档)。

在我的 iPhone 上,甚至在模拟器中也能完美运行。 有什么想法吗?

import UIKit

/// A UITabBarController subclass that allows "scroll-to-top" gestures via tapping tab bar items. You enable the functionality by simply subclassing. 
class tapBarController: UITabBarController, UITabBarControllerDelegate {

/// Determines whether the scrolling capability's enabled.
var scrollEnabled: Bool = true

private var previousIndex = 0

override func viewDidLoad() {
    super.viewDidLoad()

    delegate = self
}

/*
 Always call "super" if you're overriding this method in your subclass.
 */
func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
    guard scrollEnabled else {
        return
    }

    guard let index = viewControllers?.indexOf(viewController) else {
        return
    }

    if index == previousIndex {

        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), { [weak self] () in

            guard let scrollView = self?.iterateThroughSubviews(self?.view) else {
                return
            }

            dispatch_async(dispatch_get_main_queue(), {
                scrollView.setContentOffset(CGPointZero, animated: true)
            })
            })
    }

    previousIndex = index
}

/*
 Iterates through the view hierarchy in an attempt to locate a UIScrollView with "scrollsToTop" enabled.
 Since the functionality relies on "scrollsToTop", it plugs easily into existing architectures - you can
 control the behaviour by modifying "scrollsToTop" on your UIScrollViews.
 */
private func iterateThroughSubviews(parentView: UIView?) -> UIScrollView? {
    guard let view = parentView else {
        return nil
    }

    for subview in view.subviews {
        if let scrollView = subview as? UIScrollView where scrollView.scrollsToTop == true {
            return scrollView
        }

        if let scrollView = iterateThroughSubviews(subview) {
            return scrollView
        }
    }

    return nil
}
}

用这段代码替换它并起作用。