Tag: 快速

迭代错误数组时发生Swift内存泄漏

我对Swift比较陌生,所以我希望我不要问一个愚蠢的问题。 我有一些代码实例化一个Errortypes的数组,这些代码稍后将被迭代并打印到控制台。 当使用“泄漏”工具通过仪器运行此代码时,它显示_SwiftNativeNSError泄漏。 如果将数组types从[Error]更改为[Any] ,则泄漏消失,即使它实际上仍保持符合Error的对象。 泄漏不能用我试过的任何其他数据types或协议重现。 以下是一些示例代码: class myLeak { lazy var errors = [Error]() enum err: Error { case myFirstError } func doSomething() { errors.append(err.myFirstError) for error in errors { print(String(describing: error)) } } } // call with let myleak = myLeak(); myleak.doSomething() 调用doSomething()函数立即创build泄漏。 将[Error]()切换到[Any]()可以解决泄漏问题,但是我并不满意这个解决scheme而不理解底层问题。 这个问题也可以通过改变[Error]()来实现Error协议: [err]() 。 我也尝试创build自己的自定义协议,只是为了certificate这是由Error引起的,我只能在使用Error时重现问题; 我自己的自定义协议没有performance出这种行为。 最初,我的代码使用forEach循环迭代数组,但是我然后尝试重写它以使用forEach中的闭包导致问题的情况下的标准for循环,但是这不起作用。 我怀疑这可能是一个Swift错误(在这种情况下,我会为它打开一个问题),但也有一个机会,我错过了一个关键的理解。 如果我正在做的是不好的做法,我想了解为什么。

体系结构x86_64的未定义符号:适用于Xcode 8.3.2中的Firebase

我手动安装了firebase到我的Xcode的存储数据的目的。 我遵循从DOCS的README和集成。 但是,这个问题是,一切安装后,我得到以下编译器错误。 Undefined symbols for architecture x86_64: “_kFIRAppDiagnosticsErrorKey”, referenced from: +[FIRDiagnostics logDiagnostics:] in FirebaseCoreDiagnostics(FIRDiagnostics_0c03a82afb19aa444c2f4902b5217b60.o) “_kFIRAppDiagnosticsSDKNameKey”, referenced from: +[FIRDiagnostics logDiagnostics:] in FirebaseCoreDiagnostics(FIRDiagnostics_0c03a82afb19aa444c2f4902b5217b60.o) “_kFIRAppDiagnosticsSDKVersionKey”, referenced from: +[FIRDiagnostics logDiagnostics:] in FirebaseCoreDiagnostics(FIRDiagnostics_0c03a82afb19aa444c2f4902b5217b60.o) “_kFIRAppDiagnosticsFIRAppKey”, referenced from: +[FIRDiagnostics logDiagnostics:] in FirebaseCoreDiagnostics(FIRDiagnostics_0c03a82afb19aa444c2f4902b5217b60.o) “_kFIRServiceAuthUI”, referenced from: +[FIRDiagnostics populateLogProtoWithInstalledServices:] in FirebaseCoreDiagnostics(FIRDiagnostics_0c03a82afb19aa444c2f4902b5217b60.o) +[FIRDiagnostics mapFromServiceStringToTypeEnum:] in FirebaseCoreDiagnostics(FIRDiagnostics_0c03a82afb19aa444c2f4902b5217b60.o) “_kFIRAppDiagnosticsNotification”, referenced from: +[FIRDiagnostics load] in FirebaseCoreDiagnostics(FIRDiagnostics_0c03a82afb19aa444c2f4902b5217b60.o) “_FIRAuthStateDidChangeInternalNotificationAppKey”, […]

iOS不会收到来自Azure通知中心的推送

在我的iOS应用程序中,我尝试通过Azure移动服务添加推送通知。 我已经按照这篇文章: https : //azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-ios-get-started-push/ 但我的应用程序仍然没有收到推送通知! 在iOS开发中心,我使用Dev和Production推送证书注册了App ID。 在Azure中向Sandbox添加开发证书(.p12)。 我写了POST函数 exports.post = function(request, response) { var text = 'You\'ve just received a push!'; var push = request.service.push; push.apns.send(null, { alert: "Alert", payload: { inAppMessage: text } }, { success: function(pushResponse) { console.log("Sent iOS push:", pushResponse); response.send(statusCodes.OK, { message : 'Push send success' }); }, error: […]

OneSignal将通知推送到所有分段

我试图从pipe理设备发送推送通知到所有设备(段:“ALL”)。 我似乎无法得到它与这个代码的工作。 let data = [ "contents": ["en": "\(message)"], "included_segments": ["All"], "excluded_segments": ["None"], "ios_badgeType": "Increase", "ios_badgeCount": 1 ] OneSignal.defaultClient().postNotification(data) “无”段存在,其中有0个用户。 “全部”拥有所有活跃的用户。 当我发布通知时,我得到一个错误 错误:创build通知失败 虽然这工作没有任何问题: let data = [ "contents": ["en": "\(message)"], "include_player_ids":["20a32b7a-4254-4e03-a24c-13fe8bd91fff"], "ios_badgeType": "Increase", "ios_badgeCount": 1 ] OneSignal.defaultClient().postNotification(data)

如何删除iOS8中的WKWebview的caching?

如何删除iOS8中的WKWebview的caching? 对于iOS 9下面的代码工作。 let websiteDataTypes = NSSet(array: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeCookies]) let date = NSDate(timeIntervalSince1970: 0) WKWebsiteDataStore.defaultDataStore().removeDataOfTypes(websiteDataTypes as! Set<String>, modifiedSince: date, completionHandler:{ }) 对于iOS 8,我尝试了以下链接的解决scheme,但不会删除caching。 https://github.com/ShingoFukuyama/WKWebViewTips#cookie-cache-credential-webkit-data-cannot-easily-delete 如何删除WKWebview中的caching? 在wkwebview目标c中删除caching 如何删除WKWebview cookies http://blogs.candoerz.com/question/128462/how-to-delete-wkwebview-cookies.aspx iOS WKWebView Tips 我将不胜感激您的帮助。

立即更新CALayer子层

我有UIView它有以下结构: UIView |- layer (CALayer) |- depthLayer (CALayer) |- bodyLayer (CALayer) 对于我设置needsDisplayOnBoundsChange = true的图层 。 当我改变UIView的大小, 层立即重绘。 但他们的子层更新有一些延迟(在下一个绘制迭代)。 如何同步sublayers depthLayer和bodyLayer的图层绘制? UIView的: override func drawRect(rect: CGRect) { bodyLayer.frame = rect depthLayer.frame = CGRectOffset(rect, 0, 5) }

如何基于另一个数组的位置对数组进行sorting?

我有一个tableView ,它的风格是Right Detail 。 因此,我有2个arrays ,一个是textLabels数据,另一个是detailTextLabel 。 将会有2个“sorting”选项。 一个将按textLabels数据sorting,第二个按照detailTextlabels数据sorting。 所以,当我sorting第一个array ( textLabels array ),第二个array (detailTextLables数组) will also have to get sorted based on the first数组) will also have to get sorted based on the first 。 我知道如何sortingarrays ,但我怎么能sorting一个基于另一个array ? 下面是我对array进行sorting的方法:(这是一个Dates array 。 firstArray.sort({ (a, b) -> Bool in a.earlierDate(b) == a })

iOS:Tableview开始更新从不播放animation

我写了一些代码,当用户长按一个单元格并确认更改时,从后端和本地数据存储中删除一个post。 但是,tableview不会更新。 我已经突破了我的代码和tableView操作代码被执行,为什么我的行不被从视图中删除? let alertView = UIAlertController(title: "Really?", message: "Are you sure you want to delete this post? Once you do it will be gone forever.", preferredStyle: .Alert) alertView.addAction(UIAlertAction(title: "Delete Post", style: UIAlertActionStyle.Default, handler: { (alertView:UIAlertAction!) -> Void in let p = post.getRawPost() p.deleteInBackgroundWithBlock({ (deleted:Bool, error:NSError?) -> Void in // Remove from the local datastore […]

我如何使用UIImageView的aspectFill和alignment到顶部?

我怎样才能使用UIImageView与aspectFill和alignment顶部? 自动布局或以编程方式不介意。

如何删除Swift iOS8中的最后一张照片?

我试图从相机胶卷上得到最后一张照片并删除它。现在我得到最后一张照片,但在删除最后一张照片时遇到问题。 我试过这种方式,但是我删除了所有的照片,所以我打算构build一个新的PHFetchResult,它只包含最后一张照片,但我不知道该怎么做。 PHPhotoLibrary.sharedPhotoLibrary().performChanges( { PHAssetChangeRequest.deleteAssets(fetchResult)}, completionHandler: { success, error in NSLog("Finished deleting asset. %@", (success ? "Success" : error)) }) 感谢大家回答我的问题!