分段故障11修复?

时间:2016-09-17 16:32:53

标签: ios swift xcode

我正在尝试创建一个应用程序,您可以在一定时间内按下按钮多次点数。在过去一周左右的时间里,我一直在构建它并在我的iPhone上运行它,但是现在所有突然的Xcode都给了我并错误地“分段错误11”。我删除了我添加的代码,从故事板中删除了东西,甚至重新安装了Xcode,但没有解决问题。有关于如何修复它的文章和视频,但它们似乎都不适合我。

这是我的代码:

import UIKit
import Foundation
import AudioToolbox


// PlaySounds
class PlaySounds {

    private var soundID: SystemSoundID = 0

    public init(named name: String) {
        if let soundURL = soundURL(forName: name) {
            let status = AudioServicesCreateSystemSoundID(soundURL as CFURL, &soundID)
            if status != noErr {
                print("Unable to create sound at URL: '\(name)'")
                soundID = 0
            }
        }
    }

    public func play() {
        if soundID != 0 {
            AudioServicesPlaySystemSound(soundID)
        }
    }

    private func soundURL(forName name: String) -> URL? {

        let fileExtensions = ["m4a", "wav", "mp3", "aac", "adts", "aif", "aiff", "aifc", "caf", "mp4"]

        for fileExtention in fileExtensions {
            if let soundURL = Bundle.main.url(forResource: name, withExtension: fileExtention) {
                return soundURL
            }
        }
        print("Unable to find sound file with name '\(name)'")
        return nil
    }

    deinit {
        if soundID != 0 {
            AudioServicesDisposeSystemSoundID(soundID)
        }
    }
}

// ViewController
class ViewController: UIViewController {

    let startTimer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(UIMenuController.update), userInfo: nil, repeats: true)

    let XDSound = PlaySounds(named: "XDDDDDDD")

    @IBAction func playButtonPressed(_ sender: AnyObject) {

        XDSound.play()

    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }


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

}

错误代码:

CompileSwift normal arm64 /Users/aaa/Desktop/XD/XD/XD/ViewController.swift
    cd /Users/aaa/Desktop/XD/XD
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/aaa/Desktop/XD/XD/XD/ViewController.swift /Users/aaa/Desktop/XD/XD/XD/AppDelegate.swift -target arm64-apple-ios10.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk -I /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos -F /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos -enable-testing -g -module-cache-path /Users/aaa/Library/Developer/Xcode/DerivedData/ModuleCache -D DEBUG -serialize-debugging-options -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-generated-files.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-own-target-headers.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-all-target-headers.hmap -Xcc -iquote -Xcc /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-project-headers.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos/include -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/DerivedSources/arm64 -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/aaa/Desktop/XD/XD -emit-module-doc-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name XD -emit-module-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.d -emit-reference-dependencies-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.swiftdeps -o /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.o

0  swift                    0x000000010bf6bb6d PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x000000010bf6b5b6 SignalHandler(int) + 470
2  libsystem_platform.dylib 0x00007fffa9fdebba _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff568ee500 _sigtramp + 2895182176
4  swift                    0x000000010944b00f llvm::Value* llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>::callback_fn<getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t)::$_3>(long, swift::irgen::IRGenFunction&, llvm::Constant*) + 255
5  swift                    0x000000010944974a swift::irgen::emitLazyCacheAccessFunction(swift::irgen::IRGenModule&, llvm::Function*, llvm::GlobalVariable*, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&)> const&) + 1194
6  swift                    0x000000010944b2cc getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>&&) + 300
7  swift                    0x000000010944ae45 emitCallToTypeMetadataAccessFunction(swift::irgen::IRGenFunction&, swift::CanType, swift::ForDefinition_t) + 117
8  swift                    0x00000001094498dc swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 108
9  swift                    0x000000010948707d void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::EmitPolymorphicArguments::emit(swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::Substitution>, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&)::$_14>(long, swift::irgen::GenericRequirement) + 861
10 swift                    0x000000010947c9e1 (anonymous namespace)::PolymorphicConvention::enumerateRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 129
11 swift                    0x0000000109486bdb swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::Substitution>, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) + 459
12 swift                    0x00000001094e34f5 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 2997
13 swift                    0x00000001094ce268 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9080
14 swift                    0x00000001093f2601 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1329
15 swift                    0x00000001094b3fcb performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1259
16 swift                    0x00000001093821c7 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23687
17 swift                    0x000000010937a265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
18 swift                    0x000000010933782d main + 8685
19 libdyld.dylib            0x00007fffa9dd2255 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/aaa/Desktop/XD/XD/XD/ViewController.swift /Users/aaa/Desktop/XD/XD/XD/AppDelegate.swift -target arm64-apple-ios10.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk -I /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos -F /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos -enable-testing -g -module-cache-path /Users/aaa/Library/Developer/Xcode/DerivedData/ModuleCache -D DEBUG -serialize-debugging-options -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-generated-files.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-own-target-headers.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-all-target-headers.hmap -Xcc -iquote -Xcc /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-project-headers.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos/include -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/DerivedSources/arm64 -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/aaa/Desktop/XD/XD -emit-module-doc-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name XD -emit-module-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.d -emit-reference-dependencies-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.swiftdeps -o /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.o 
1.  While emitting IR SIL function @_TFC2XD14ViewControllercfT7nibNameGSqSS_6bundleGSqCSo6Bundle__S0_ for 'init' at /Users/aaa/Desktop/XD/XD/XD/ViewController.swift:56:40

它在错误“swift:56:40”的底部说,我认为这意味着第56行的第40个字符,但是所有这些都是ViewController的开始括号。帮助

1 个答案:

答案 0 :(得分:0)

初始化定时器的行会导致错误。

您无法在班级的顶层调用目标/操作方法。

将变量声明为隐式展开的可选

.results tr[visible='false'],
.no-result{
  display:none;
}

.results tr[visible='true']{
  display:table-row;
}

.counter{
  padding:8px; 
  color:#ccc;
}

并在<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="form-group pull-right"> <input type="text" class="form-control" id="search" placeholder="search"> </div> <span class="counter pull-right"></span> <table class="table table-condensed table-hover results"> <thead> <tr> <th>Index</th> <th>Column1</th> <th>Column2</th> <th>Column3</th> </tr> <tr class="warning no-result"> <td colspan="4"><i class="fa fa-warning"></i> No result</td> </tr> </thead> <tbody> <tr> <td>112</td> <td>Content112</td> <td>Content2</td> <td>Content329</td> </tr> <tr> <td>123</td> <td>SomeOtherContent112</td> <td>SomeOtherContent123</td> <td>SomeOtherContent3</td> </tr> <tr> <td>329</td> <td>DifferentContent123</td> <td>DifferentContent2</td> <td>DifferentContent329</td> </tr> </tbody> </table>

中对其进行初始化
var startTimer : Timer!

或使用闭包

将变量声明为viewDidLoad
 override func viewDidLoad() {
      super.viewDidLoad()
      startTimer = Timer.scheduledTimer(timeInterval: 0.4, 
                                              target: self, 
                                            selector: #selector(UIMenuController.update), 
                                            userInfo: nil, 
                                             repeats: true)
  }

并调用它来启动计时器

lazy