swift3

Successfully stored String value to keychain, but always failed to read it out

时光毁灭记忆、已成空白 提交于 2019-12-22 13:46:46
问题 I am developing an iOS project with XCode8 + Swift3. I have created the following two functions to store string to keychain and read it back from keychain: var query: [String: Any] = [ kSecClass as String: kSecClassGenericPassword, kSecAttrService as String: "my service", kSecAttrAccount as String: "my-key" ] func storeString(value: String) -> Bool { if let data = value.data(using: .utf8) { // delete data if exist SecItemDelete(query as CFDictionary) // add value to query query[kSecValueData

Set SKShapeNode frame to calculateAccumutedFrame

早过忘川 提交于 2019-12-22 12:33:26
问题 This issue has been happening for days: I cannot set the specific frame I need. I need my SKShapeNode frame to be the bounding box around a circle so that it is an inscribed circle to the frame. The blue is the current frame and the red is the frame I want it to be. I am creating the SKShapeNode like this: init(level: Int, from: SKSpriteNode, fromScene: GameScene) { self.level = level self.from = from self.fromScene = fromScene bezierPath = UIBezierPath(arcCenter: CGPoint.zero, radius:

Set SKShapeNode frame to calculateAccumutedFrame

别等时光非礼了梦想. 提交于 2019-12-22 12:33:14
问题 This issue has been happening for days: I cannot set the specific frame I need. I need my SKShapeNode frame to be the bounding box around a circle so that it is an inscribed circle to the frame. The blue is the current frame and the red is the frame I want it to be. I am creating the SKShapeNode like this: init(level: Int, from: SKSpriteNode, fromScene: GameScene) { self.level = level self.from = from self.fromScene = fromScene bezierPath = UIBezierPath(arcCenter: CGPoint.zero, radius:

Creating a type bound to a certain range in Swift

。_饼干妹妹 提交于 2019-12-22 12:15:18
问题 Say I have a function that takes an Int , but not just any Int . It could be: Only natural numbers Ints from 2 to 200 etc Assume that the number of valid values is too big to make the use of an Enum that explicitly declares all of them a feasible approach. Is there a way to declare a type that specifies a closed range in Swift? I tried playing around with Range , but it doesn't work as expected. 回答1: The best I can think of is to wrap an Int in a struct with an initializer that enforces your

Bonjour Service Browser with Swift does not fetch serviceinfo

丶灬走出姿态 提交于 2019-12-22 12:02:21
问题 The service I want to connect to is published via Bonjour. I can find all the info with the Bonjour Browser, however if I try to gather the data programmatically, the only value I get, is the name of the service. The NetService delegate is set and the function netServiceWillPublish is called. The functions DidNotPublish or DidPublish are not executed. The function netServiceBrowser gets all published netServices, but all properties are set to the default value of the datatype. import UIKit

Set local notifications for particular days and time swift 3

独自空忆成欢 提交于 2019-12-22 11:35:43
问题 In my app, i want to add local notifications. The scenario will be that the user can select any time and days from Mon to Sun. For example, if the user selects Mon, Thur and Sat as days and time as 11:00 pm, so now the user should be notified at all the selected days and that particular time. Code: let notification = UNMutableNotificationContent() notification.title = "Danger Will Robinson" notification.subtitle = "Something This Way Comes" notification.body = "I need to tell you something,

NSTextStorageDelegate's textStorage(_,willProcessEditing:,range:,changeInLength:) moves selection

泄露秘密 提交于 2019-12-22 11:16:33
问题 I'm trying to implement a syntax-coloring text editor that also does things like insert whitespace at the start of a new line for you, or replace text with text attachments. After perusing the docs again after a previous implementation had issues with undoing, it seems like the recommended bottleneck for this is NSTextStorageDelegate's textStorage(_,willProcessEditing:,range:,changeInLength:) method (which states that Delegates can change the characters or attributes. , whereas

How to compress data in swift 3?

ぐ巨炮叔叔 提交于 2019-12-22 10:43:35
问题 I have some files in file manager in Swift 3. I want to upload them, but when I will convert them into base 64, their size will be huge! so I want to compress the data before converting it into base 64. Here is my code for converting: for i in 0...(rows?.count)! - 1 { let filePath = filesurl[fileManagerViewController.selectedFileIndex[i]] do { let fileData = try Data.init(contentsOf: filePath) let fileStream:String = fileData.base64EncodedString(options: NSData.Base64EncodingOptions.init

How can I get the URL from webView in swift

て烟熏妆下的殇ゞ 提交于 2019-12-22 10:26:59
问题 I have question, how can I fetch the url from the webView ? I perform the following code and I get the nil Code I'm trying : override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(true) webView.loadRequest(URLRequest(url: URL(string: "https://www.youtube.com/watch?v=Vv2zJErQt84")!)) if let text = webView.request?.url?.absoluteString{ print(text) } } 回答1: You are not getting url because webView has not finished the loading of that requested URL , you can get that URL in

macOS, Swift 3: How to get data back after segue?

南笙酒味 提交于 2019-12-22 10:24:37
问题 For example: I have two UIViewController s. The first has a button and a NSTextField , and the second has a NSTextField only. When I click the button on the first controller — the second controller shows as popover window. Making a transfer of some data from first controller to second is not big deal — I use a segue. But what I should to do to transfer data back — from the popover window to main window? For example: we open the popover window, type some text in NSTextField , and I want to get