Kwnstantinos Natsios Kwnstantinos Natsios - 3 months ago 16
iOS Question

Segmentation fault 11 on xcode 7.3.1

Weird error in

Archive
Process
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


The file that has the error is the following
tabBarController.swift


Which helps me to make the following: If the user pushes a tab Bar button then the scroll view goes to the top.

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)
}
}
}


If I comment the hole file then i have no error. Also I cant figure out from the code what is the error (which was working until 2 days ago and it was archived).

On my iPhone and even in the simulator works perfect.
Any idea?

Answer
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
}
}

Replaced it with this code and worked.