草庐IT

EXC_GUARD

全部标签

c++ - 为什么 dispatch_queue_create 在 Swift 中给出 EXC_BAD_ACCESS 错误?

我正在将一些代码从C++移植到使用GrandCentralDispatch的Swift,我发现dispatch_queue_create似乎根本不起作用的奇怪错误。例如,在我的C++基类header中,我会声明dispatch_queue_tm_WorkQ;在初始化器中,放入m_ResultQ=dispatch_queue_create("com.myapp.mHitsUpdateQueue",0);...一切都是光荣的。我已经在我的类里面用Swift尝试过这个,在类级别声明:varresultQueue:dispatch_queue_t...在初始化器中,我有(除其他外)这条线res

ios - SKNode.removeFromParent() EXC_BAD_ACCESS

我注意到我的Swift项目中有一个奇怪的行为,并以这种方式在一个空的SpriteKit项目中重现了它:classGameScene:SKScene{overridefuncdidMoveToView(view:SKView){letsprite=SKSpriteNode(imageNamed:"Spaceship")self.addChild(sprite)//sprite.removeFromParent()letsprite2=SKSpriteNode(imageNamed:"Spaceship")self.addChild(sprite2)sprite2.removeFromPa

ios - NSManagedObject 在 Swift 中实现协议(protocol)的 EXC_BAD_ACCESS 错误

我有以下两种方法:funcisAuthenticated()->Bool{varcurrentUser:CurrentUser?=self.getCurrentUser()ifcurrentUser==nil{returnfalse}self.token=getUserToken(currentUser!.username)ifself.token==nil{returnfalse}if!tokenIsValidForUser(self.token!,user:currentUser!){returnfalse}returntrue}functokenIsValidForUser(to

ios - 在 guard 语句 swift 中呈现一个 ViewController

我正在尝试呈现viewcontroller,以防状态(Int?)为零,如下所示:guardletstatusCode=statuselse{DispatchQueue.main.async(){letinitViewController=self.storyboard!.instantiateViewController(withIdentifier:"SignInViewController")self.present(initViewController,animated:false,completion:nil)}return}我想知道这是否是最佳实践,因为在呈现ViewCont

random - Swift 数组访问触发 EXC_BREAKPOINT

这是我的代码(largeAsteroids.count永远不会为0):varlargeAsteroids=[[SKTexture]]()funcrandomLargeAsteroidTextures()->Array{leti=Int(arc4random())%largeAsteroids.countreturnlargeAsteroids[i]//thislinetriggersEXC_BREAKPOINT}当我执行我的代码时,我没有收到任何错误,但我收到了一个EXC_BREAKPOINT。我确保没有任何断点,并且在索引i处有一个有效对象。首先我将SKTexture更改为AnyOb

swift - 在 Swift 中使用 guard 或 if case 从枚举中提取值

我有案例枚举:caseone(value:myClassOne)casetwo(value:myClassTwo)我想检查那个枚举的值。现在我结束了:switchself.model!{case.one://Great,mycaseheredefault:break}但我更想做类似的事情:ifcaseself.model(letvalue)ismyClassOne{//dosmth}//Notcompiling是否有简单的方法来简单地提取枚举值并检查它是否符合某些条件或类是否相等? 最佳答案 这是正确的语法:ifcase.one(v

animation - swift : animator() causes EXC_BAD_ACCESS

自beta5以来,我注意到在OSX10.10下隐式动画有一些奇怪的行为。调用动画代理有时会导致应用程序崩溃。我设置了一个非常简单的自定义View。这是完整的代码:importCocoaimportQuartzCoreclassAnimatedView:NSView{varfirstColor:NSColor=NSColor.blackColor(){didSet{self.needsDisplay=true}}varsecondColor:NSColor=NSColor.whiteColor(){didSet{self.needsDisplay=true}}overridefuncdr

ios - DismissViewControllerAnimated EXC_Bad_ACCESS 为真

我正在按照苹果从WWDC发布的教程“查看ViewController内部”进行操作,以创建自定义ViewController(此处为视频:https://developer.apple.com/videos/wwdc/2014/,示例代码为:https://developer.apple.com/library/ios/samplecode/LookInside/Introduction/Intro.html)。我主要是复制他们的objective-C并将其逐行翻译成Swift,除了用手势点击隐藏覆盖viewController之外,我几乎已经开始工作了。当我打电话时:funcdimm

ios - AVCaptureSession 开始运行 exc_bad_access iOS 10 Swift 3

我在启动AVCaptureSession时发生exc_bad_access崩溃:ifcaptureSession.isRunning==false{captureSession.startRunning()}注意:它在Swift2.2中工作。我只有在迁移到Swift3后才会遇到此崩溃。任何想法! 最佳答案 是的!zsteed的答案有效添加到您的Info.plist:NSCameraUsageDescriptionAllowustoscandocumentsandcaptureimages.

swift - 在 Init 中使用 Guard?

除了当我执行像“fds”这样的随机字符串时,一切都运行顺畅,我将如何正确有效地使用守卫来防止此类错误?init(weatherData:[String:AnyObject]){city=weatherData["name"]as!StringletweatherDict=weatherData["weather"]![0]as![String:AnyObject]description=weatherDict["description"]as!Stringicon=weatherDict["icon"]as!StringletmainDict=weatherData["main"]as