JSON
CloneableJSON Documentation
The CloneableJSON struct provides a flexible way to work with JSON-like data structures in Swift, allowing for schema validation and easy manipulation of nested data. This documentation will focus on using CloneableJSON with the provided schema for a measure pole task list.
JSON Schema Guide
Schema GuideSchema
The schema we'll be working with is as follows:
{
"measure_pole_task_list": {
"type": "array",
"description": "Array of tasks associated with the pole",
"array_type": "object",
"properties": {
"id": {
"type": "string",
"description": "Id of the task or attachment"
},
"name": {
"type": "string",
"description": "Name of the task to be performed on the pole"
},
"inspection_phase": {
"type": "string",
"description": "Phase of the inspection this task will be presented. ar or photo"
},
"design_height": {
"type": "number",
"description": "Expected height for the task in meters"
},
"actual_height": {
"type": "number",
"description": "The actual measured height in meters"
},
"status": {
"type": "string",
"description": "Status of the item"
}
}
}
}Creating a CloneableJSON instance
To create a CloneableJSON instance with this schema:
Working with CloneableJSON
Creating the Measure Pole Task List
To create the measure pole task list according to the schema:
Adding Multiple Tasks
To add multiple tasks:
Accessing and Modifying Data
To access and modify data in the CloneableJSON structure:
Validating the Data
To validate the data against the schema:
Best Practices
Always use the appropriate
CloneableDataTypefor each field (CloneableStringfor strings,CloneableNumberfor numbers).Validate the data against the schema after making changes to ensure consistency.
Use optional binding and type checking when accessing data to handle potential mismatches safely.
When modifying nested structures, make sure to reassign the modified value at each level of the hierarchy.
Use descriptive variable names that match the schema structure for clarity.
By following these guidelines and examples, you can effectively use the CloneableJSON struct to work with the measure pole task list data structure in a type-safe and schema-validated manner.
Last updated

