swift3

How to reset the Badge app icon number?

泄露秘密 提交于 2021-02-19 06:57:05
问题 I integrated the Push Notification to the CloudKit so that every change in the iCloud will pop up a notification on my iPhone and the badge app icon number will add one correspondingly. However, when I used the code: application.applicationIconBadgeNumber = 0 to reset that number in the applicationDidBecomeActive(_ application: UIApplication) , I noticed that the badge app icon number truly disappeared but if another new notification came again, the number won't start from one again as

Unexpected Core Data Multithreading Violation

可紊 提交于 2021-02-18 20:40:36
问题 I'm using Apple's concurrency core data debugger. -com.apple.CoreData.ConcurrencyDebug 1 From time to time I got __Multithreading_Violation_AllThatIsLeftToUsIsHonor__ , even I'm almost sure threading is not violated. This is part of code where exception occurs (code is part of protocol that extends NSManagedObject): public static func find(arrayBy predicate: NSPredicate, sort: [NSSortDescriptor] = [], limit: Int? = nil) -> [Self] { let fetchRequest = NSFetchRequest<Self>(entityName: "\(Self

iOS - How to predefine TextView line height

南楼画角 提交于 2021-02-18 19:40:39
问题 I've some UITextView declared as the following lazy var inputTextView: UITextView = { let tv = UITextView() tv.tintColor = UIColor.darkGray tv.font = UIFont.systemFont(ofSize: 17) tv.backgroundColor = UIColor.white return tv }() I've been searching how can I predefine the line height for this UITextView so whenever I write a long text, when it reaches the end of the line and goes to the following line, the spacing would be bigger than the default. I've tried using the following inside the

How to select external microphone

前提是你 提交于 2021-02-18 08:13:27
问题 I've successfully written a simple recording app for iOS that uses AVAudioRecorder. So far it works with either the internal microphone or an external microphone if it's plugged in to the headphone jack. How do I select an audio source that is connected through the USB "lightning port"? Do I have to dive into Core Audio? Specifically I'm trying to connect an Apogee Electronics ONE USB audio interface. 回答1: Using AVAudioSession, get the availableInputs. The return value is an array of

Extracting address elements from a String using NSDataDetector in Swift 3.0

大憨熊 提交于 2021-02-18 06:58:15
问题 I'm attempting to use NSDataDetector to addresses from a string. I've taken a look at NSHipster's article on NSDataDetector as well as Apple's NSDataDetector documentation. I've got the following method to the point where it'll pull addresses out of a string: func getAddress(from dataString: String) -> [String] { let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.address.rawValue) let matches = detector.matches(in: dataString, options: [], range: NSRange(location: 0,

How to access the Terminal's $PATH variable from within my mac app, it seems to uses a different $PATH

微笑、不失礼 提交于 2021-02-17 20:47:20
问题 I'm trying to make a mac app where the user can type in commands just like they would in the mac terminal, I got most of it working however I found out that the $PATH variable of apps run from the finder or xcode is different than the $PATH variable the Terminal uses. I can run commands and also found a way to add a predefined path to the application's $PATH variable but I need a way to automatically read the Terminal's $PATH variable and copy it to the Application's $PATH variable. This

Completion gets called soon

ぐ巨炮叔叔 提交于 2021-02-15 07:43:45
问题 I have the following functions. I'm trying to pass allItems array into the completion block of requestItems , but I get a crash as it says it's nil. I removed the completion to check that item has a value and it does. That means that the completion executes before the for loop. Is there another approach for this? Something like Promises in Javascript that will execute the completion when the for loop has finished. func requestItems(_ data: [String: Any], completion: (Bool, [Item]) -> Void) {

macOS Printing in Swift

£可爱£侵袭症+ 提交于 2021-02-10 14:32:21
问题 Please note this is not an iOS question. I have an NSView-based app (i.e. not document-based), and I’d like to bolt on a printing subsystem. I can get NSViews in my main controller to print ok. However, I want to have a special view constructed just for printing. The view should not show in the app’s window. The view contains two NSTextFields, two NSTextViews, and 5 labels. I cannot seem to figure out a way to do this. I have tried various forms of these examples: Add an NSView to my main

macOS Printing in Swift

自闭症网瘾萝莉.ら 提交于 2021-02-10 14:31:14
问题 Please note this is not an iOS question. I have an NSView-based app (i.e. not document-based), and I’d like to bolt on a printing subsystem. I can get NSViews in my main controller to print ok. However, I want to have a special view constructed just for printing. The view should not show in the app’s window. The view contains two NSTextFields, two NSTextViews, and 5 labels. I cannot seem to figure out a way to do this. I have tried various forms of these examples: Add an NSView to my main

Swift convert string to date output wrong date

和自甴很熟 提交于 2021-02-10 13:24:24
问题 I want to convert dateStartString = “28/02/2018” in to Date and compare that converted date with today date. when i convert dateStartString the converted date is "2018-02-27 18:30:00 UTC" .why its output is wrong date? here is my code var dateStartString = "28/02/2018" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd/MM/yyyy" guard let dateStartDate = dateFormatter.date(from: dateStartString) else { fatalError("ERROR: Date conversion failed due to mismatched format.") } let