Tag: swift4

如何检测ARKit中的垂直飞机?

如何实现垂直平面检测(即墙壁)? let configuration = ARWorldTrackingSessionConfiguration() configuration.planeDetection = .horizontal //TODO

警告:“字符”已弃用:请直接使用string或子string

字符 – String的实例属性,从Xcode 9.1(beta) 它是/是一个非常有用的属性,从string获取子string,但不赞成和Xcodebuild议使用substring 。 我试图检查一下SO问题和苹果开发者教程/指导原则。 但没有看到任何解决scheme/替代build议。 这里是警告消息: '字符'已弃用:请使用string或子string 我有很多string操作是使用属性characters执行/处理的。 任何人有关于此更新的任何想法/信息?

Swift 4 – UIApplication.registerForRemoteNotifications()只能从主线程调用

Xcode 9(iOS 11)在注册Push(远程)通知时显示错误/警告。 这是错误信息 这里是代码,我试过了: let center = UNUserNotificationCenter.current() center.delegate = self center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in if error == nil{ UIApplication.shared.registerForRemoteNotifications() } } 错误/警告线: UIApplication.shared.registerForRemoteNotifications() 如何解决这个问题?

Xcode 9:使用Swift 3.1编译的模块不能在Swift 4.0中导入

更新到Xcode 9之后,我试图build立我的一个项目。 我使用FacebookLogin窗格。 我在FacebookLogin / LoginButton.swift中有一个编译器错误 @testable import FacebookCore ❌ Module compiled with Swift 3.1 cannot be imported in Swift 4.0 在我的目标的构build设置中,Swift语言版本设置为Swift 3.2 。 我想我需要等待Facebook更新他们的pod? 还是有其他build议? 谢谢 !

导航栏rightbaritem图像button错误的iOS 11

此代码在ios10中正常工作。 我得到我的标签和一个图像button,这是用户的照片configuration文件,圆形圆….好吧。 但是当运行xcode 9 ios11模拟器时,我把它拉长了。 button框架必须是32×32,当检查模拟和获取视图,并告诉xcode描述视图我得到的输出为170×32或类似的东西。 inheritance我的代码。 let labelbutton = UIButton( type: .system) labelbutton.addTarget(self, action:#selector(self.toLogin(_:)), for: .touchUpInside) labelbutton.setTitleColor(UIColor.white, for: .normal) labelbutton.contentHorizontalAlignment = .right labelbutton.titleLabel?.font = UIFont.systemFont(ofSize: 18.00) let button = UIButton(type: .custom) button.addTarget(self, action:#selector(self.toLogin(_:)), for: .touchUpInside) button.frame = CGRect(x: 0, y: 0, width: 32, height: 32) button.setTitleColor(UIColor.white, for: .normal) button.setTitleColor(UIColor.white, for: .highlighted) var buttomItem : […]

将NSString转换为NSDate(并再次返回)Swift 4解决scheme可用

我如何将“ 01/02/10 ”(意思是2010年2月1日)的NSString / String转换为NSDate / Date ? 我又怎么能把date再次变成一个string呢?

条码在迅速4

我正在尝试将mi应用程序升级到swift 4,但是条形码阅读器不工作。 我已经隔离了条码阅读器的代码,仍然不能正常工作。 相机工作,但它不检测条码。 代码在swift 3 iOS 10上工作得很好。 这是完整的代码 import AVFoundation import UIKit class ViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate { var captureSession: AVCaptureSession! var previewLayer: AVCaptureVideoPreviewLayer! override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.black captureSession = AVCaptureSession() let videoCaptureDevice = AVCaptureDevice.default(for: AVMediaType.video) let videoInput: AVCaptureDeviceInput do { videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice!) } catch { return } […]

在Swift 4模式下使用Swift 3 @objc推断是否被弃用?

简而言之,在使用Xcode 9 Beta时,我遇到了以下警告: 在Swift 4模式下使用Swift 3 @objc推断已被弃用。 请解决不推荐使用的@objc推理警告,使用“使用不推荐使用的Swift 3 @objc推断”日志来testing代码,并禁用Swift 3 @objc推理。 经过一番调查,我仍然不知道如何解决这个问题。 我将不胜感激关于如何解决这个问题的任何提示,以及对正在发生的事情的解释。 我的目标是更好地理解我的代码正在发生什么。

如何在Swift 4中使用string切片下标?

我有以下简单的代码写在Swift 3中: let str = "Hello, playground" let index = str.index(of: ",")! let newStr = str.substring(to: index) 从Xcode 9 beta 5中,我得到以下警告: ' substring(to:) '已被弃用:请使用String切片下标与“部分范围”运算符。 如何在Swift 4中使用部分范围的切片下标 ?

关键值观察(KVO)在Swift中是否可用?

如果是这样的话,在Objective-C中使用键值观察时,是否存在其他不存在的关键差异?