swift3

NSFetchedResultsController deleteCache in Swift 3

老子叫甜甜 提交于 2020-01-01 09:05:48
问题 Currently migrating to swift 3 and can't quite figure out what the parser wants for NSFetchedResultsController.deleteCache(withName: "rootCache") With this syntax, I'm getting a "Type 'String?' does not conform to protocol 'ExpressibleByStringLiteral'" error when building. 回答1: The error message is misleading. As of Swift 3, NSFetchedResultsController is a generic type open class NSFetchedResultsController<ResultType : NSFetchRequestResult> : NSObject { } and the following should work:

NSFetchedResultsController deleteCache in Swift 3

烂漫一生 提交于 2020-01-01 09:05:06
问题 Currently migrating to swift 3 and can't quite figure out what the parser wants for NSFetchedResultsController.deleteCache(withName: "rootCache") With this syntax, I'm getting a "Type 'String?' does not conform to protocol 'ExpressibleByStringLiteral'" error when building. 回答1: The error message is misleading. As of Swift 3, NSFetchedResultsController is a generic type open class NSFetchedResultsController<ResultType : NSFetchRequestResult> : NSObject { } and the following should work:

WKWebView on link click listener?

眉间皱痕 提交于 2020-01-01 08:24:14
问题 Does there exist something like a onLinkClickListener in the WKWebView class? I tried googling it but found nothing, I also found some unanswered questions on stackoverflow of simillar type. The reason I need a linkClickListener is that, when I click on a link and the page did not load yet, it does not load the website. I also could create a fancy loading screen, when the page is loading with the listener. 回答1: You can do it like this add WKNavigationDelegate to your class class

Metal crash upon adding SKSpriteNode to SKEffectNode

牧云@^-^@ 提交于 2020-01-01 08:18:16
问题 -[MTLDebugRenderCommandEncoder setScissorRect:]:2028: failed assertion `(rect.x(0) + rect.width(1080))(1080) must be <= 240' I am getting this crash when adding a simple SKSpriteNode to a SKEffectNode with the following code SKSpriteNode *warpSprite = [SKSpriteNode spriteNodeWithImageNamed:@"art.scnassets/symbol.png"]; SKEffectNode *entryEffectsNode = [[SKEffectNode alloc] init]; [entryEffectsNode addChild:warpSprite]; [self addChild:entryEffectsNode]; I have not touched these nodes anywhere

Migrating UIWebView delegate to WKWebView delegate method

我的未来我决定 提交于 2020-01-01 07:31:12
问题 I am working on migrating UIWebView to WKWebView. I have changed all the Delegate methods. I need WKWebView delegate methods equal to below UIWebView delegate method. The app is working fine. but login session is not retaining UIWebView: extension WebViewController: UIWebViewDelegate { func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool { guard let url = request.url else { return true } guard !url.absoluteString.contains

Sending an on-the-fly created QR Code UIImage by AirDrop fails

≯℡__Kan透↙ 提交于 2020-01-01 06:10:31
问题 I am creating a QR Code on the fly and storing it as UIImage. Now I want to be able to send it using the UIActivityViewController but somehow it fails: func generateQRCode(from string: String) -> UIImage? { let data = string.data(using: String.Encoding.ascii) if let filter = CIFilter(name: "CIQRCodeGenerator") { filter.setValue(data, forKey: "inputMessage") let transform = CGAffineTransform(scaleX: 3, y: 3) if let output = filter.outputImage?.applying(transform) { return UIImage(ciImage:

Sending an on-the-fly created QR Code UIImage by AirDrop fails

拥有回忆 提交于 2020-01-01 06:09:13
问题 I am creating a QR Code on the fly and storing it as UIImage. Now I want to be able to send it using the UIActivityViewController but somehow it fails: func generateQRCode(from string: String) -> UIImage? { let data = string.data(using: String.Encoding.ascii) if let filter = CIFilter(name: "CIQRCodeGenerator") { filter.setValue(data, forKey: "inputMessage") let transform = CGAffineTransform(scaleX: 3, y: 3) if let output = filter.outputImage?.applying(transform) { return UIImage(ciImage:

Swift arc4random_uniform(max) in Linux

纵饮孤独 提交于 2020-01-01 04:34:05
问题 I'm working with Swift in Ubuntu, and I am getting an error that arc4random is an unresolved identifier. More information on this known bug here. Basically, the function only exists in BSD distros. I've tried module mapping header files, apt-getting packages, and I get more and more errors, which is not worth pursuing since this one function is not used very often. Are there any functions to get pseudo random numbers with an upper-bound parameter that is compatible with Swift in Linux? 回答1:

Swift 3 NSCache Generic parameter 'KeyType' could not be inferred

一曲冷凌霜 提交于 2020-01-01 04:03:11
问题 This code worked in Swift 2.x: /// An internal in-memory cache private var dataCache = NSCache.init() In Swift 3 it causes compilation error: Generic parameter 'KeyType' could not be inferred Why is that so and how should I refactor this (Migration tool did not pick this up)? 回答1: In the first Swift 3 betas NSCache has been changed to Cache . In the latest betas (currently 5) it has been reverted to NSCache . Anyway NSCache is now a generic. public class NSCache<KeyType : AnyObject,

How do I make a fetch request using NSManagedObject's new fetchRequest function?

。_饼干妹妹 提交于 2019-12-31 20:07:45
问题 In iOS 10 the CoreData team added a new "fetchRequest" method to NSManagedObject. It looks like this: public class func fetchRequest() -> NSFetchRequest<NSFetchRequestResult> Which, from what I understand, allows us to replace this: let request = NSFetchRequest<MyEntity>(entityName: "MyEntity") with this: let request = MyEntity.fetchRequest() However, when I try to make a simple request like this: let request = MyEntity.fetchRequest() do { results = try request.execute() } catch let error {