For this purpose, we can create a special condition: right-click the breakpoint and in the Condition field type end = start: We want the new breakpoint to stop the program execution only when the end and start dates of the conference are the same. Set a new breakpoint at line 21 ( Ctrl+F8) and remove the previous one at line 17 by clicking its icon in the gutter. For convenience, we will display the conference data on the Watches tab. Let's add a conditional breakpoint that will stop the program execution only when calling textDates() for one-day conferences. This happens because the textDates() method doesn’t handle the conferences with the same start and end dates correctly. Set a breakpoint right before the decode() method is called, namely, at the following line: Let's try to use the formatted decoding strategy instead by injecting new code at runtime. It will bring you to the dateDecodingStrategy property declaration in the Foundation.swift file. For example, choose dateDecodingStrategy and press F4. You can select a necessary symbol on the Variables tab and press F4 (or select Jump to Source from the context menu) to navigate to its source code. We see that our JSONDecoder uses the deferredToDate decoding strategy that can handle dates in double format only, whereas we have string date values in our JSON. If the value is truncated, click View to open it in a popup: You can see all the properties of the JSONDecoder object when expanding this variable. The error that we’ve got ( Expected to decode Double but found a string/data instead) most likely relates to the JSONDecoder object stored in the decoder variable. The Threads & Variables tab displays a stack of method/function calls on the left and a list of variables available in the current context on the right. The program execution will stop at the line that throws the error, and the Debug tool window will appear: For example, you can add breakpoints that hit only when encountering an unhandled Swift error ( Swift) or an Objective-C exception ( Objective-C).Ĭlick Done to apply the changes and start a debugging session by pressing Shift+F9 or clicking on the toolbar. You can add several exception breakpoint with different settings. This will enable a default exception breakpoint which hits if any exception is thrown: In the Breakpoints dialog that opens, select the Exception Breakpoints checkbox on the left. Let's set an exception breakpoint to locate the code that throws this error: Set an exception breakpointįrom the main menu, select Run | View Breakpoints or press Ctrl+Shift+F8. UnderlyingError: nil)): file /path/to/the/project/ac_tutorial_debugging/iOSConferences/Model/Data.swift, line 27 TypeMismatch(Swift.Double, (codingPath:, debugDescription: "Expected to decode Double but found a string/data instead.", if let bestPlayer = players.Fatal error: Cannot parse conferencesData.json: Array: Use optionals when you might have an instance to return from a function, or you might not. You can even write concurrent code with simple, built-in keywords that define asynchronous behavior, making your code more readable and less error prone. Memory is managed automatically using tight, deterministic reference counting, keeping memory usage to a minimum without the overhead of garbage collection. To best support international languages and emoji, strings are Unicode-correct and use a UTF-8-based encoding to optimize performance for a wide variety of use cases. Inferred types make code cleaner and less prone to mistakes, while modules eliminate headers and provide namespaces. Even better, you don’t even need to type semi-colons. Named parameters are expressed in a clean syntax that makes APIs in Swift even easier to read and maintain. Swift is the result of the latest research on programming languages, combined with decades of experience building Apple platforms.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |