小编Bar*_*tal的帖子

如何解决SceneKit渲染器“ EXC_BAD_ACCESS(代码= 1,地址= 0xf000000010a10c10)”?

这是我遇到的错误,请查看所附图片以获取更多信息。

com.apple.scenekit.scnview-renderer(17):EXC_BAD_ACCESS(代码= 1,地址= 0xf000000010a10c10)

这是错误的日志: 有关错误的更多信息

我可以在调用以下函数时重现此错误,但前提是此函数在一秒钟内被多次调用。如果用户快速点击该按钮以循环到下一辆可用的汽车,则会发生这种情况。

如您所见,我尝试将其包装在a中DispatchQueue以解决我的问题。

您还会注意到,我创建了一个Bool alreadyCyclingCars来跟踪该cycleCarNext()函数是否已完成,然后再允许再次调用它。

这个功能主要是通过所有的迭代unlockedCarsunlockedCars阵列。

如果汽车的类型与我们当前正在寻找的汽车相匹配,我会打破循环。

然后我们确定当前汽车的索引,以查看我需要显示的下一辆汽车是否是数组中的下一辆汽车(如果有)(如果没有),我们到达了数组的末尾,因此我显示了第一辆汽车在数组中。

有谁比我对此了解更多?真的很感谢,谢谢!

func cycleCarNext() {
        DispatchQueue.main.async { [weak self] in
            guard let self = self else { return }
            if !self.alreadyCyclingCars {
                self.alreadyCyclingCars = true
                var indexOfCurrentCar = 0
                for (index, car) in UserData.shared.unlockedCars.enumerated() {
                    if car.type == self.overlayScene.currentCarOnDisplay {
                        indexOfCurrentCar = index
                        break
                    }
                }

                if indexOfCurrentCar < UserData.shared.unlockedCars.count - 1 {
                    let nextCar = UserData.shared.unlockedCars[indexOfCurrentCar+1]
                    self.playerNode.removeFromParentNode()
                    self.playerNode = …
Run Code Online (Sandbox Code Playgroud)

scenekit swift

11
推荐指数
1
解决办法
1335
查看次数

在闭包之外使用"自我"有没有明显的好处?

我注意到,即使没有明确要求(即在闭包之外),业内的一些人也会使用self关键字.

例:

import UIKit
import MapView
import CoreLocation

class viewController: UIViewController, MKMapViewDelegate, CLLocationDelegate {

    let mapView = MKMapView()
    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.mapView.delegate = self
        self.mapView.showsUserLocation = true

        self.locationManager.delegate = self
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
    }
}
Run Code Online (Sandbox Code Playgroud)

运行时间方面是否有明显的好处?或者这纯粹是一种风格选择?

self ios swift

8
推荐指数
1
解决办法
203
查看次数

如何对特定于区域设置的本地通知进行单元测试

我刚刚在我的应用中添加了本地通知。当应用区域设置regionCode(即Locale.current.regionCode)为“ US”或“ CA”时,才触发这些通知。我对语言环境感兴趣language

我还将要编写补充的测试用例,但是一旦我知道如何编写一个测试用例,其他的就自然而然地遵循了。

因此,我的问题是:如何将Locale注入测试中(请参阅参考资料testSuccessfulNotificationDelivery())?

LocalNotificationTests.swift

class LocalNotificationTests: XCTestCase {

    let notification1 = LocalNotification(toTriggerInSeconds: 5)
    let notification2 = LocalNotification(toTriggerInSeconds: 6)

    // This object manages LocalNotifications 
    // by building them into UNUserNotifications
    // and then scheduling them using UNUserNotificationCenter.
    let notificationManager = NotificationManager()

    func testSuccessfulNotificationDelivery() {

        // setup locale and use it for testing, somehow
        let  = Locale(identifier: "en_CA")

        // The answer to my question would …
Run Code Online (Sandbox Code Playgroud)

locale ios localnotification swift unusernotificationcenter

8
推荐指数
1
解决办法
311
查看次数

iOS App编译并运行,仅显示黑屏

以下是摘要:

  • 项目建设成功
  • 在XS Max模拟器上运行时:该应用程序显示启动屏幕,但是此后仅显示黑色,而没有运行时错误。
  • 在任何其他模拟器上运行时:该应用程序显示启动屏幕,但是,该应用程序显示黑色,但控制台读取。

libMobileGestalt MobileGestalt.c:890:此平台不支持MGIsDeviceOneOfType

我已经将应用程序从Swift 2更新到4.2。大多数错误修复只是在更新语法。

任何有助于解决此问题的见解将不胜感激!

private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: Any]?) -> Bool {
    setConstants()

    window = UIWindow(frame: UIScreen.main.bounds)
    window!.rootViewController = RootViewController.sharedInstance
    window!.makeKeyAndVisible()

    preloadKeyboard()

    return true
}
Run Code Online (Sandbox Code Playgroud)

RootViewController的共享实例:

static let sharedInstance = RootViewController(nibName: "RootViewController", bundle: nil)
Run Code Online (Sandbox Code Playgroud)

为什么这不是重复的问题:

  • MGc90不是我要解决的主要错误(黑屏是)
  • 链接问题的解决方案无法解决问题
  • Sol#1 Xcode 9.4.1产生相同的错误
  • Sol#2从didFinishLaunchingWithOptions中删除private只会产生一个错误
  • Sol#3很好地了解了该错误的含义,并帮助我理解了为什么它在XS Max上未显示错误。
  • Sol#4我没有断点或警报以继续
  • Sol#5我没有模棱两可的布局警告
  • Sol#6部署目标很好
  • Sol#7我知道较新的iPhone型号不会产生错误,但仍显示黑屏
  • Sol#8字体已加载
  • Sol#9另一个变更模拟器。

xcode ios ios-simulator swift

5
推荐指数
0
解决办法
950
查看次数

如何使用递归来产生权力之和?

我试图只使用递归(并没有内置函数)编写一个函数,它消耗两个数字,x和y并产生总和

1 + x + x^2 + ... + x^(y-1) + x^y

请注意,我正在寻找一种使用for/while循环的方法,因为我还没有学习它们.到目前为止,我有以下功能:

def power_addition (x, y):
    i = 0
    if i < y:
        i = i+1
        return x**i + power_addition (x, y)
    else:
        return x**i
Run Code Online (Sandbox Code Playgroud)

据我所知,代码中断有一个特殊原因.

python

0
推荐指数
1
解决办法
206
查看次数