swift3

How do i convert HexString To ByteArray in Swift 3

拜拜、爱过 提交于 2020-01-14 14:51:06
问题 I'm was trying to convert hexString to Array of Bytes([UInt8]) I searched everywhere but couldn't find a solution. Below is my swift 2 code func stringToBytes(_ string: String) -> [UInt8]? { let chars = Array(string) let length = chars.count if length & 1 != 0 { return nil } var bytes = [UInt8]() bytes.reserveCapacity(length/2) for var i = 0; i < length; i += 2 { if let a = find(hexChars, chars[i]), let b = find(hexChars, chars[i+1]) { bytes.append(UInt8(a << 4) + UInt8(b)) } else { return

Cannot convert value of type 'String?' to expected argument type 'URL'

佐手、 提交于 2020-01-14 14:25:30
问题 I'm trying to load data from file which was in main bundle. When I use this code let path = Bundle.main.path(forResource: "abc", ofType: "txt") let dataTwo = try! Data(contentsOf: path)\\ error here Also I tried to convert String to URL let dataTwo = try! Data(contentsOf: URL(string: "file://\(path)")!) But after execution am getting this fatal error: unexpectedly found nil while unwrapping an Optional value 回答1: You may want to use .url instead: let url = Bundle.main.url(forResource: "abc",

Unable to instantiate NSFetchedResultController with generic type AnyObject in Swift 3

时光总嘲笑我的痴心妄想 提交于 2020-01-14 13:05:53
问题 I'm experimenting with CoreData in Swift 3 and have come up against a very bizarre circular compiler error in Xcode 8 beta. NSFetchedResultsController needs a generic type parameter and AnyObject has worked fine up until now. The compiler throws the error: Type 'AnyObject' does not conform to protocol 'NSFetchRequestObject' To make me extra confused, if you delete the type parameter, XCode then says: Reference to generic type NSFetchedResultsController requires argument in `<...>` and

cellForRowAt indexPath is not being called with reloadData() method

独自空忆成欢 提交于 2020-01-14 06:01:19
问题 In Swift 3, I am trying to create a "Filter" view that lets the user filter posts in a table view by category and by date. Currently, the filter view is presented modally and is dismissed when you click "Done". I have not set up the date/category functionality yet. First, I am just trying to get the tableView to update to show only 3 of the posts rather than 10 . To do this, I set destination.numPosts = 3 in my FilterViewController . Using print statements, it can be seen that the

Hide placeholder Programatically using swift 3x

孤人 提交于 2020-01-14 05:51:04
问题 How to hide the placeholder of TextField programmatically using Swift 3x ? 回答1: You can not hide the placeholder of UITextField , but you can set it to empty String. self.textField.placeholder = "" Now textField doesn't show any placeholder later on if you want to show the placeholder simply set it with String that you want. self.textField.placeholder = "Enter name" 来源: https://stackoverflow.com/questions/41421850/hide-placeholder-programatically-using-swift-3x

Adding objects over camera view in app (Swift 3) not under camera view?

那年仲夏 提交于 2020-01-14 05:33:11
问题 I have an overlay over the camera view made up of red circles, stored in the Assets.xcasset ImgOverlay placeholders, and the cameraview (preview) appears behind - or underneath - the overlay. That's fine. As it should be. When I run the app on the iPhone, the overlay appears as it should. See Img.1 But I also have a blue circle being drawn, that is Underneath the Camera View, and only appears if the camera view is missing. That is, Turned off, or run on a simulator. See Img.2 below. Image 1.

Can you send objects other than strings in URLQueryItems?

廉价感情. 提交于 2020-01-14 03:46:16
问题 Ok, I am building an iMessage app and to transfer data back and forth I have to use URLQueryItem s. I am working with an SKScene and need to transfer Int s, CGPoint s, images, etc. Reading Apple's documentation and my own attempts it seems like you can only store strings in URLQueryItem s. As this us the only way to pass data back and forth, is there a (better) way to store other types of data? Currently I have been doing this: func composeMessage(theScene: GameScene) { let conversation =

Iterating over an array by range

☆樱花仙子☆ 提交于 2020-01-13 14:01:10
问题 I have an array: [1, 2, 3, 4, 5, 6...100] I am looking to iterate over this array by 5, specifically: Take the first 5 numbers of the array and get the average, move on to the next 5 numbers and get the average, and so on.. I have tried numerous methods such as a Dequeue and for loops but have not been able to get the outcome desired. 回答1: You need to use a progression loop to iterate each 5 element and use reduce to sum the subsequence then divide the total by the subsequence elements count:

Open phone settings when button is clicked in my app

自作多情 提交于 2020-01-13 11:36:22
问题 I recently upgraded to Xcode 8 and converted my code to Swift 3. I am making a custom keyboard (extension) which worked perfectly fine till iOS 9, but i am facing a couple of issues in iOS 10. The container app of the custom keyboard contains a button which directs the user to the keyboard settings to add the keyboard Issue: This button click is not working in iOS 10 i.e the user is not directed to the settings. I have configured the URL Schemes in my project and have tried the following code

Swift & PromiseKit: Resolving ALL promises from a loop

泪湿孤枕 提交于 2020-01-13 09:44:10
问题 I'm looking for a solution in Swift3 to resolve a dynamic number of promises all at once, e.g. like this sample in JavaScript: var promises = []; for(var i = 0; i < 5; i++) { var promise = $http.get('/data' + i); promises.push(promise); } $q.all(promises).then(doSomethingAfterAllRequests); https://daveceddia.com/waiting-for-promises-in-a-loop/ There was a library call 'Craft' for Swift2 that could do that (https://github.com/supertommy/craft), but it's no longer maintained. Does anyone know