Tag: swift3

无法将“__NSArrayI”(0x10df73c08)types的值转换为“NSDictionary”(0x10df74108)

let url = "http://xyz/index_main.php?c=webservices&a=get&e=007" Alamofire.request(url, method: .post, parameters: nil, encoding: JSONEncoding.default) .responseJSON { response in print(response) //to get status code if let status = response.response?.statusCode { switch(status){ case 201: print("example success") default: print("error with response status: \(status)") } } //to get JSON return value if let result = response.result.value { let JSON = result as! […]

Swift 3 Xcode 8中的FileManager和urlsForDirectory错误

我刚刚从testing版3到Xcode 8testing版4,但出于什么原因,我得到这个错误,没有任何错误的工作或发布,直到testing版4.这里是错误“ Value of type 'FileManager' has no member 'urlsForDirectory' “ 我的代码: func setupRecorder(){ let audioSession:AVAudioSession = AVAudioSession.sharedInstance() //ask for permission if (audioSession.responds(to: #selector(AVAudioSession.requestRecordPermission(_:)))) { AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in if granted { print("Permission Granted\n") //set category and activate recorder session do { //—- let fileManager = FileManager.default let urls = fileManager.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask) //—- let […]

什么是正确的方式,使用“init”或“didmove”?

语言:Swift 3.0 — IDE:Xcode 8.0 beta 2 —项目:iOS游戏(SpriteKit) 我为iOS创build了一个游戏,而且我知道苹果对于接受应用程序/游戏的规则非常严格。 所以我想知道哪个是设置游戏的正确方法。 我从谷歌学习创build一个新的SpriteKit项目,并执行以下设置: 在GameViewController.swift清除viewDidLoad()并添加所有这一切: override func viewDidLoad() { super.viewDidLoad() let skView = self.view as! SKView let scene = GameScene(size: skView.bounds.size) scene.scaleMode = .aspectFit skView.presentScene(scene) } 在GameScene.swift中删除所有内容,并保留下面的代码: import SpriteKit class GameScene: SKScene { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } override init(size: CGSize) { super.init(size: size) // […]

如何在swift3中获得CNLabeledValue的本地化string

在迅速2我使用CNLabeledValue.localizedStringForLabel(phoneNumber.label)并正常工作。 在swift 3我试过这行CNLabeledValue.localizedString(forLabel: phoneNumber.label!)但得到generic parameter 'ValueType' could not be inferred错误 如何在swift3中获取CNLabeledValue的本地化string?

Swift 3以编程方式创buildUILabel并添加NSLayoutConstraints

你好,我正在试图创build一个标签编程,并添加NSLayoutConstraints,使它在超级视图中居中,无论屏幕的大小和方向等我看了,但没有find一个示例遵循。 这是我有什么: let codedLabel:UILabel = UILabel() codedLabel.frame = CGRect(x: 100, y: 100, width: 200, height: 200) codedLabel.textAlignment = .center codedLabel.text = alertText codedLabel.numberOfLines=1 codedLabel.textColor=UIColor.red codedLabel.font=UIFont.systemFont(ofSize: 22) codedLabel.backgroundColor=UIColor.lightGray let heightConstraint:NSLayoutConstraint = NSLayoutConstraint(item: codedLabel, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 200) let widthConstraint:NSLayoutConstraint = NSLayoutConstraint(item: codedLabel, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, […]

在Swift 3.0中生成随机字节

我想在Swift 3.0中使用SecRandomCopyBytes生成随机字节。 这是我在Swift 2.2中做的 private static func generateRandomBytes() -> String? { let data = NSMutableData(length: Int(32)) let result = SecRandomCopyBytes(kSecRandomDefault, 32, UnsafeMutablePointer<UInt8>(data!.mutableBytes)) if result == errSecSuccess { return data!.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0)) } else { print("Problem generating random bytes") return nil } } 在Swift 3中,我试图这样做,因为我知道unsafemutablebytes的概念现在是不同的,但它不允许我返回。 如果我注释掉返回部分,它仍然说Generic Parameter ResultType could not be inferred fileprivate static func generateRandomBytes() […]

没有'+ ='候选产生预期的上下文结果types'Int'

我一直在更新我的Swift代码Swift 3(真的很兴奋),到目前为止这么好。 但是我没有想到要更新一些代码。 我知道我错过了很简单的东西,但我只是看不到什么。 这里是我在Swift 2.2中的: var column = 0 […] for item in 0 ..< collectionView!.numberOfItemsInSection(0) { […] column = column >= (numberOfColumns – 1) ? 0 : ++column } ++column在Swift 3中当然被弃用,赞成column += 1 但是,在这种情况下,它会产生一个错误: 没有'+ ='候选人产生预期的上下文结果types'Int' 由于这行代码( column = column >= (numberOfColumns – 1) ? 0 : column += 1 )产生一个错误,我尝试了以下几点: var newCol […]

Swift 3奇怪的崩溃(types推断)

我找不到一个更合适的标题。 这是场景: final class Something : UIViewController { fileprivate var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() self.tableView = UITableView(frame: CGRect.zero, style: .plain) self.tableView.translatesAutoresizingMaskIntoConstraints = false //Delegate, register cell, … self.view.addSubview(self.tableView) let views/*: [String: Any]*/ = ["table": self.tableView] //THIS LINE NOW WILL CRASH self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "|-0-[table]-0-|", options: [], metrics: nil, views: views)) self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[table]-0-|", options: [], […]

swift 3中的dispatchqueue显示为未parsing的标识符

我正尝试在主线程上asynchronous录制/录制video。 但是,当我调用dispatch.main.async ,我总是得到错误: use of unresolved identifier DispatchQueue 从WWDC到苹果的文档,我都到处寻找,但我没有看到这种types的弃用证据。 这里是代码: if !self.cameraEngine.isRecording { if let url = CameraEngineFileManager.temporaryPath("video.mp4") { self.cameraButton.setTitle("stop recording", forState: []) self.cameraEngine.startRecordingVideo(url, blockCompletion: { (url: NSURL?, error: NSError?) -> (Void) in if let url = url { DispatchQueue.main.async { self.cameraButton.setTitle("start recording", for: .normal) CameraEngineFileManager.saveVideo(url, blockCompletion: { (success: Bool, error: Error?) -> (Void) in […]

无法将“Date”传递给NSPredicate(格式:…)而没有“as CVarArg”

这是我应该如何传递一个Date到NSPredicate.init(format predicateFormat: String, arguments argList: CVaListPointer) 。 let endDate = Date() NSPredicate(format: "endDate == %@", endDate as CVarArg) 它看起来有点笨拙,我怀疑我做错了什么。