swift3

Taking photo with custom camera Swift 3

懵懂的女人 提交于 2019-12-17 19:00:21
问题 in Swift 2.3 I used this code to take a picture in custom camera: func didPressTakePhoto(){ if let videoConnection = stillImageOutput!.connection(withMediaType: AVMediaTypeVideo) { stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: { (sampleBuffer, error) -> Void in if sampleBuffer != nil { let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer) let dataProvider = CGDataProviderCreateWithCFData(imageData) let

Create a paginated PDF—Mac OS X

試著忘記壹切 提交于 2019-12-17 18:43:32
问题 I am making a Mac app (in Swift 3 using Xcode 8, Beta 5) with which the user can make a long note and export it as a PDF. To create this PDF, I am using Cocoa's dataWithPDF: method with the following code: do { // define bounds of PDF as the note text view let rect: NSRect = self.noteTextView.bounds // create the file path for the PDF if let dir = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.allDomainsMask, true).first

FIRInstanceID/WARNING STOP!! Will reset deviceID from memory [Xcode : Console Log]

三世轮回 提交于 2019-12-17 18:27:54
问题 After updating to XCode 8 GM(Swift 3) Firebase started logging these error's in the Console:- FIRInstanceID/WARNING STOP!! Will reset deviceID from memory. FIRInstanceID/WARNING Failed to fetch default token Error Domain=com.firebase.iid Code=6 "(null)" FIRInstanceID/WARNING Failed to retrieve the default GCM token after 5 retries 回答1: Apparently Enabling your app's KeyChain Sharing in Capabilities does the trick! After enabling your capabilities , app.entitlements should look something like

Subclassing NSManagedObject with swift 3 and Xcode 8 beta

ぐ巨炮叔叔 提交于 2019-12-17 18:18:21
问题 I've began to try use Core data with swift 3 and Xcode 8 beta. When I try to generate NSManagedObject subclasses from core data model and Create NSManagedObject subclass… option in Editor menu, Xcode 8 beta generates three files one of them is _COREDATA_DATAMODELNAME_ +CoreDataModel.swift with the following content: import Foundation import CoreData ___COREDATA_DATAMODEL_MANAGEDOBJECTCLASSES_IMPLEMENTATIONS___ In addition, the content of this file shows two warnings: Expressions are not

Receiving Location even when app is not running in Swift

試著忘記壹切 提交于 2019-12-17 17:59:17
问题 Still very new to Swift. I have come from an Android background where there is BroadcastReceiver that can deliver location info to a service even though the app isn't running. So I was looking for something similar in iOS/Swift and it appears that before this wasn't possible but it may be now. I am developing for iOS 10 but would be great if it was backwards compatible. I found startMonitoringSignificantLocationChanges which I can execute to start delivering location updates, although this

Detect if the application in background or foreground in swift

て烟熏妆下的殇ゞ 提交于 2019-12-17 17:36:55
问题 is there any way to know the state of my application if it is in background mode or in foreground . Thanks 回答1: [UIApplication sharedApplication].applicationState will return current state of applications such as: UIApplicationStateActive UIApplicationStateInactive UIApplicationStateBackground or if you want to access via notification see UIApplicationDidBecomeActiveNotification Swift 3+ let state = UIApplication.shared.applicationState if state == .background || state == .inactive { //

Swift 3 unable to append array of objects, which conform to a protocol, to a collection of that protocol

别说谁变了你拦得住时间么 提交于 2019-12-17 16:59:48
问题 Below I have pasted code which you should be able to paste into a Swift 3 playground and see the error. I have a protocol defined and create an empty array of that type. I then have a class which conforms to the protocol which I try to append to the array but I get the below error. protocol MyProtocol { var text: String { get } } class MyClass: MyProtocol { var text = "Hello" } var collection = [MyProtocol]() var myClassCollection = [MyClass(), MyClass()] collection.append(myClassCollection)

How do you override layerClass in swift 3?

断了今生、忘了曾经 提交于 2019-12-17 16:44:29
问题 I'm trying to override the method layerClass() in swift 3 but I'm getting the error Method does not override any method from its superclass . In swift 2.x I was doing like this, does anyone know the new syntax? override func layerClass() -> AnyClass { return CAGradientLayer.self } 回答1: Please check the latest reference when you find Method does not override any method from its superclass with code which worked in former versions of Xcode/Swift. Declaration class var layerClass: AnyClass { get

Swift ImagePickerController didFinishPickingMediaWithInfo not fired

爱⌒轻易说出口 提交于 2019-12-17 16:32:00
问题 I use the ImagePickerController , to grab a profile image. The user has a button. The button triggers the CamRoll function. When the button is clicked, the normal ImagePickerViewController appears, but the didFinishPickingMediaWithInfo isn't called. In an earlier version of Swift/Xcode, the same code was called. This is my code. import UIKit class AnnonseViewController: UIViewController, UIImagePickerControllerDelegate { @IBOutlet var Image: UIImageView! override func viewDidLoad() { super

Choosing units with MeasurementFormatter

故事扮演 提交于 2019-12-17 16:31:35
问题 This is similar to a question I asked yesterday but the answer I got doesn't seem to work in this case. I'm getting altitude values in meters from Core Location. I want to display these in a localized form. As an example, the altitude where I am right now is 1839m above sea level. This should be displayed as 6033 feet. The best I can do with MeasurementFormatter is "1.143 mi". let meters : Double = 1839 let metersMeasurement = Measurement(value: meters, unit: UnitLength.meters) let