Post

Replies

Boosts

Views

Activity

Reply to Problem with matching arrays and indexes
Can you show more examples?Let's say we have:let arrayValues = ["apples", "bannanas", "cherry", "date", "eggplant", "dorito"] let x = 1 let y = 3Then, what is the desired output? Some boolean value `true` or `false`? An array? Or some integers?Please show some examples, input(s) - output(s). You should better omit intermediate values and just show the final result.
Nov ’19
Reply to Support different orientations in controllers embedded in a navigation
My problem is that this method never gets called. Any thoughts?Please clarify which method do you mean by this method. "navigationControllerSupportedInterfaceOrientations" or preferredInterfaceOrientationForPresentation?Assuming navigationControllerSupportedInterfaceOrientations, you may be mistaking something when implementing the delegate method `navigationControllerSupportedInterfaceOrientations` or setting the delegate of the navigation controller.I created a simple project with navigation controller and navigationControllerSupportedInterfaceOrientations is called multiple times. Please show your code.
Nov ’19
Reply to Extend JSONDecoder to allow for models to be serialized differently based on endpoint
In this simple case as in your example, you have no need to do anything special.(Please show valid JSON texts, with easily testable code and data, more readers would test them and you would get more responses.)struct Book: Codable { var author: String var title: String var libraryId: String? var sectionNumber: String? var length: String? var reviews: String? enum CodingKeys: String, CodingKey { case author = "Author" case title = "Title" case libraryId = "LibraryId" case sectionNumber = "SectionNumber" case length = "Length" case reviews = "Reviews" } } struct Result: Codable { var book: Book enum CodingKeys: String, CodingKey { case book = "Book" } } let endpoint1Text = """ { "Book": { "Author": "James", "Title": "JamesBook", "LibraryId": "387fh384fh3i09", "SectionNumber": "870D" } } """ let endpoint2Text = """ { "Book": { "Author": "James", "Title": "JamesBook", "Length": "870", "Reviews": "9/10" } } """ do { let result1 = try JSONDecoder().decode(Result.self, from: endpoint1Text.data(using: .utf8)!) print(result1) let result2 = try JSONDecoder().decode(Result.self, from: endpoint2Text.data(using: .utf8)!) print(result2) } catch { print(error) }Tested in Playgrounds, I get this.Result(book: __lldb_expr_5.Book(author: "James", title: "JamesBook", libraryId: Optional("387fh384fh3i09"), sectionNumber: Optional("870D"), length: nil, reviews: nil))Result(book: __lldb_expr_5.Book(author: "James", title: "JamesBook", libraryId: nil, sectionNumber: nil, length: Optional("870"), reviews: Optional("9/10")))Your actual model may be more complex and there may be some difficulties, but I cannot say any more without seeing it.
Dec ’19
Reply to Closure?
Currently, one of the most popular ways is using `Result` type as an argument to the completion handler: func submitPost(post: User, completion:((Result<String, Error>) -> Void)?) { //... let encoder = JSONEncoder() do { let jsonData = try encoder.encode(post) request.httpBody = jsonData print("jsonData: ", String(data: request.httpBody!, encoding: .utf8) ?? "no body data") } catch { completion?(.failure(error)) //<- } let config = URLSessionConfiguration.default let session = URLSession(configuration: config) let task = session.dataTask(with: request) { (responseData, response, responseError) in guard responseError == nil else { completion?(.failure(responseError!)) //<- return } if let data = responseData, let utf8Representation = String(data: data, encoding: .utf8) { print("response: ", utf8Representation) completion?(.success(utf8Representation)) //<- } else { print("no readable data received in response") completion?(.success("no readable data received in response")) //or you may want to pass .failure with your own error } } task.resume() }You can use it like this: submitPost(post: myPost) { (result) in switch result { case .success(let value): print(value) //...use value here case .failure(let error): print(error) fatalError(error.localizedDescription) } }
Dec ’19
Reply to How can I get the head rotation value with ARKit3?
Doesn't faceanchor.transform.columns.2 contain head rotation values?No. Transformation matrix is sort of combined representation of rotation, translation and scaling.Any of the rows does not contain rotation values separately.You can find how to separate the rotation matrix from the transformation matrix, if you learn 4x4 transformation matrix theory.I do not understand what you mean by rotation values, but there may be some ways to calculate it from the transformation matrix.You would have a better chance that some ARKit experts find your your question, if you choose an appropriate topic area: ARKit
Dec ’19
Reply to Value of optional type 'String?' must be unwrapped to a value of type 'String'
So, what do you want to ask?---Generally, if you want to make per-character based mapping on String:- `components(separatedBy:)` and `joined(separator:)` are not good tools- You need to define the output for the characters not contained in the `map`I would write it as:var text = "hello" let map: [Character: Character] = ["0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9","a":"ᴀ","b":"ʙ","c":"ᴄ","d":"ᴅ","e":"ᴇ","f":"ғ","g":"ɢ","h":"ʜ","i":"ɪ","j":"ᴊ","k":"ᴋ","l":"ʟ","m":"ᴍ","n":"ɴ","o":"ᴏ","p":"ᴘ","q":"ǫ","r":"ʀ","s":"s","t":"ᴛ","u":"ᴜ","v":"ᴠ","w":"ᴡ","x":"x","y":"ʏ","z":"ᴢ","A":"A","B":"B","C":"C","D":"D","E":"E","F":"F","G":"G","H":"H","I":"I","J":"J","K":"K","L":"L","M":"M","N":"N","O":"O","P":"P","Q":"Q","R":"R","S":"S","T":"T","U":"U","V":"V","W":"W","X":"X","Y":"Y","Z":"Z"] let string = String(text.map {ch in map[ch, default: ch]}) print(string) //->ʜᴇʟʟᴏ
Dec ’19
Reply to exc bad instruction
Please clarify what you want to ask.---When you show error message, better take more parts of the error info shown in the debug console:Fatal error: Index out of rangeAnd the exact line number of the errorcharArray[i] = map[charArray[i]] ?? textYour `charArray` is an Array of only one element "hello", but your `i` gets greater than 0.Thats the reason for the error Index out of range.But you have no need to (and should not) use `components(separatedBy:)`, so check my answer for you another question.
Dec ’19
Reply to Value of optional type 'String?' must be unwrapped to a value of type 'String'
I am wondering why it saysValue of optional type 'String?' must be unwrapped to a value of type 'String'right behindThe lefthand side of your assignment expression (`charArray[i]`) is of type `String`,but the righthand side (`map[charArray[i]]`) is of type `String?` (aka `Optional<String>`).You need to unwrap an Optional value to assign it to a non-Optional.But your current code has some more flaws and you may need to fix them first.
Dec ’19