2016-08-14 114 views
1

奇怪的错误在Archive过程with Xcode 7.3.1 (7D1014)分段故障11 7.3.1

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上,甚至在模拟器中工作完美。 有什么想法?

回答

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

用此代码替换它并且工作。