Tag: swift4

我如何重构我的代码在主线程上调用AppDelegate?

我最近开始将我的项目从Swift3 / Xcode8迁移到Swift4 / Xcode9。 我的应用程序在运行时崩溃,因为主线程清理程序只允许在主线程上访问UIApplication.shared.delegate ,导致启动时崩溃。 我有下面的代码,在Swift 3中工作正常 – static var appDelegate: AppDelegate { return UIApplication.shared.delegate as! AppDelegate; } 我的代码中的其他类可以访问appDelegate。 我需要找出一种方法来从主线程返回UIApplication.shared.delegate 。 注意 :从访问appDelegate位置使用DispatchQueue.main.async{}块不是一个选项。 只需要在static var appDelegate声明中使用它。 寻找一个聪明的解决方法。 相关的崩溃消息: 主线程检查器:UI API在后台线程上调用: – [UIApplication delegate] PID:1094,TID:30824,线程名称:(none),队列名称:NSOperationQueue 0x60400043c540(QOS:未知),QoS:0

扩展中的声明不能覆盖Swift 4中的错误

我有一个扩展名: public extension UIWindow { override public func topMostController()->UIViewController? { … } } 但对于我topMostController我得到下一个错误: Declarations in extensions cannot override yet error 它适用于Swift 3.1,但对于Swift 4,我得到这个错误。 如何解决? 他们在Swift 4中改变了什么?

如何在Swift 4中编写一个可解码的JSON,其中密钥是dynamic的?

我有这样的JSON。 我需要使用Swift 4在我的iOS应用程序中创build相应的Decodable结构。 { "cherry": { "filling": "cherries and love", "goodWithIceCream": true, "madeBy": "my grandmother" }, "odd": { "filling": "rocks, I think?", "goodWithIceCream": false, "madeBy": "a child, maybe?" }, "super-chocolate": { "flavor": "german chocolate with chocolate shavings", "forABirthday": false, "madeBy": "the charming bakery up the street" } } 在制作Decodable Struct时需要帮助。 如何提到像cherry , odd和super-chocolate的未知键。

无法加载优化模型 – GoogleMaps SDK IOS

从CocoaPods安装Google Maps SDK后,我收到了这个错误。 CoreData: annotation: Failed to load optimized model at path '/Users/nabeel/Library/Developer/CoreSimulator/Devices/96078737-8063-4BC1-97DB-7FECEC6835D9/data/Containers/Bundle/Application/972CD686-82DD-4357-9CDD-65A735D82190/My-APP-Beta.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileVersionID.omo' CoreData:注释:无法在path加载优化模型'/ Users / nabeel / Library / Developer / CoreSimulator / Devices / 96078737-8063-4BC1-97DB-7FECEC6835D9 / data / Containers / Bundle / Application / 972CD686-82DD-4357-9CDD -65A735D82190 / My-APP-Beta.app / GoogleMaps.bundle / GMSCacheStorage.momd / StorageWithTileVersionID.omo'CoreData:annotation:无法在path'/ Users / nabeel / Library / Developer / CoreSimulator […]

AudioHardware.cpp:1200:AudioObjectRemovePropertyListener:AudioObjectRemovePropertyListener:没有给定ID 0的对象

在一个快速的项目,我试图启动的AVPlayer,由于某种原因,它导致我的例外说 AudioHardware.cpp:1200:AudioObjectRemovePropertyListener:AudioObjectRemovePropertyListener:没有给定ID为0的对象。 我想这个问题是与我的url。 这是我的代码 func initPlayer() { let url:NSURL = NSURL(string:"https://purelight1-163000.appspot.com/api/user/v2/media/track/60/sample")! self.playerItem = AVPlayerItem(url: url as URL) self.player=AVPlayer(playerItem: self.playerItem!) let playerLayer=AVPlayerLayer(player: self.player!) playerLayer.frame = CGRect(x: 0, y: 0, width: 10, height: 50) // actually this player layer is not visible self.view.layer.addSublayer(playerLayer) }

ReplayKit:startRecording()完成处理程序从不input

问题描述 即使显示“允许在$ AppName中logging屏幕”popup窗口,也不会inputstartRecording()完成处理程序。 偶尔会显示“在$ AppName中允许屏幕录制”popup窗口。 这也发生在我删除应用程序,重新启动设备,并干净/build立在项目上。 我正在使用iOS 11和Xcode 9的iPad Air 2。 研究 这个问题在早期版本中似乎也是一个问题,请看这里: replaykit startrecording有时从来没有进入完成处理程序我不能批准closuresWiFi或有一个稳定的互联网连接解决这个问题,这个问题也没有解决在iOS 11。 这是我正在使用的代码: @IBAction func recordButtonTapped(_ sender: UIButton) { if !recorder.isRecording { startRecording(sender) } else { stopRecording(sender) } } private func startRecording(_ sender: UIButton) { guard recorder.isAvailable else { print("Recording is not available at this time.") // Display UI for recording […]

使用Swift 4.0编译的模块不能在Swift 4.0.1中导入

不过,我已经使用相同的Xcode重新编译框架,它仍然给我这个错误。 适用于两者的基本SDK iOS 11.1 两个Swift语言版本Swift 4.0 不使用豆荚/迦太基 我希望有人知道

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议? 谢谢 !

如何以编程方式触发UITableViewCell editActions?

我在我的tableviewcell上做了一些自定义的编辑操作。 当我滑动时,它工作正常,但我想知道是否有任何方法来触发这些行动,当我点击细胞。 另外,我看到很多人只是回答类似的问题, tableView.setEditing(true, animated: true) 虽然这不是我正在寻找的解决scheme。 我希望在没有按下另一个button的情况下立即显示操作。 谢谢。

封闭元组不支持在Xcode9 Swift4中解构

在Xcode 9中的Swift4的光泽项目之后 我得到以下错误,我不知道 封闭元组参数'(key:_,value:_)'不支持解构 码: extension Dictionary { init(elements: [Element]) { self.init() for (key, value) in elements { self[key] = value } } func flatMap<KeyPrime, ValuePrime>(_ transform: (Key, Value) throws -> (KeyPrime, ValuePrime)?) rethrows -> [KeyPrime:ValuePrime] { return Dictionary<KeyPrime, ValuePrime>(elements: try flatMap({ (key, value) in return try transform(key, value) })) } } 此时try flatMap({ (key, […]