swift2

Memory leak on NSPredicate that used in fetch request to fetch NSManagedObject

江枫思渺然 提交于 2019-12-12 17:22:26
问题 According to the instrument I have memory leak on the NSPredicate. How can I avoid this memory leak? what went wrong? The code as the following: Note : Default Manager is Singleton self.editingContext is a child context that has a parent context (main context) The output of this function (JobType) is NSManagedObject that use in the parent NSManagedObject (e.g job.type = jobType) func defaultJobType() -> JobType? { let fetchRequest = NSFetchRequest(entityName: JobType.entityName()); let

RequestStateForRegion after startMonitoringForRegion in Swift

倖福魔咒の 提交于 2019-12-12 16:40:00
问题 When I start monitoring a region like locationManager.startMonitoringForRegion(tGeoFence[wert][wert2]) and try to determine if it is already entered right after that like this: for region in locationManager.monitoredRegions { if let cireg = region as? CLCircularRegion { if cireg.identifier == tGeoFence[wert][wert2].identifier { locationManager.requestStateForRegion(cireg) } } } doesn't work, cause the registration of the region is not finished when the 2nd part of the code is executed.

How to turn the iPhone camera flash on/off swift 2?

偶尔善良 提交于 2019-12-12 15:47:52
问题 I was looking how to turn on/off the iPhone's camera flash and I found this: @IBAction func didTouchFlashButton(sender: AnyObject) { let avDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) // check if the device has torch if avDevice.hasTorch { // lock your device for configuration avDevice.lockForConfiguration(nil) // check if your torchMode is on or off. If on turns it off otherwise turns it on if avDevice.torchActive { avDevice.torchMode = AVCaptureTorchMode.Off } else

UIWebView's “loadData” method does not accept nil for baseURL in Swift 2

百般思念 提交于 2019-12-12 14:18:39
问题 I don't want to pass any value to baseURL parameter in loadData method of UIWebView . In Swift 1.2, nil works fine: self.loadFundInfo.loadData(responseData, MIMEType: contentType, textEncodingName: "", baseURL: nil) In Swift 2.0, how to do the same thing? I am getting this error: Nil is not compatible with expected argument type NSURL 回答1: The error message is rather self-explanatory: the baseURL parameter must now be of type NSURL , not NSURL? (not an optional anymore, so it can not be nil).

SpriteKit PhysicsBody non-rectangular collision

╄→尐↘猪︶ㄣ 提交于 2019-12-12 13:15:49
问题 pipeUp.physicsBody = SKPhysicsBody(rectangleOfSize: pipeUp.size) in this coding I used the rectangleOfSize for collision physics body, but if I want to use by pixel just the shape of the image, what I should use instead of rectangleOfSize ? 回答1: You should make a CGPath that is the shape of your object, and use SKPhysicsBody 's init(polygonFromPath path: CGPath) as described here 回答2: I'd use KnightOfDragon's method with the addition of the size : parameter like this: pipeUp.physicsBody =

iOS - Alamofire v2 Basic Auth not working

☆樱花仙子☆ 提交于 2019-12-12 13:08:12
问题 So I'm sending a basic auth request to Bing Image Search to grab some image data, and it was working great, right until I updated to the latest version of Alamofire (1.3 -> 2.0.2), which I had to do because 1.3 wasn't even close to compatible with XCode 7. Anyway, here is my code: let credentials = ":\(Settings.bingApiKey)" let plainText = credentials.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) let base64 = plainText!.base64EncodedStringWithOptions

How to download the file from Parse.com using the REST API?

拟墨画扇 提交于 2019-12-12 12:15:10
问题 I found this question at Parse.com file download question, however, it only mentions that the file can be downloaded from the Url. Also, the Parse.com REST Documentation only discuss upload file and associated with an Object. I tried to access the URL only, but it returns an error. Can anyone help with an example in Swift and using the REST API, how to download the actual file once you get the URL after querying the object? This is the error I get: Error Domain=NSURLErrorDomain Code=-1100

how to create grayscale image from nsimage in swift?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 11:37:51
问题 I created two applications: one for mac and one for iPhone. iPhone sends the video frames it captured to mac using MultipeerConnectivity framework. I have managed to find code for converting an UIimage to grayscale using this code: func convertToGrayScale(image: UIImage) -> UIImage { let imageRect:CGRect = CGRectMake(0, 0, image.size.width, image.size.height) let colorSpace = CGColorSpaceCreateDeviceGray() let width = image.size.width let height = image.size.height let bitmapInfo =

Add Parse.com 1.11.0 to watchOS 2

泄露秘密 提交于 2019-12-12 11:35:37
问题 In the Parse SDK update to 1.11.0 it says it supports watchOS and tvOS. I was wondering how I can add the frameworks to my watchOS app using Cocoapods. The pod file contains pod 'Parse' and I have run pod update then pod install but when I add a bridging header to the watchOS 2 Extension it says file not found. Do you know what I should be doing? Thank you 回答1: It seems like the QuickStart instructions have not been updated for watchOS 2. I couldn't find any information in the announcement

Swift 2.0 version of struct GeneratorOf<T>

余生颓废 提交于 2019-12-12 11:24:14
问题 It appears that struct GeneratorOf<T> {…} is not available in in Swift 2.0. Does anyone know what, if anything, replaces this struct? Thanks 回答1: GeneratorOf was replaced by AnyGenerator but you have to call a global function instead of the initializer to make one: anyGenerator(anotherGenerator) anyGenerator{ /* pass "next function" (as closure) */ } 回答2: In Swift 2 GeneratorOf is replaced by class AnyGenerator<Element> . 来源: https://stackoverflow.com/questions/32255249/swift-2-0-version-of