InterviewSolution
Saved Bookmarks
| 1. |
Consider a scenario where I have two different system storage which requires IDs in different data types. One system will deal int values only and others in string values only. Create a generic protocol with a single property “ids” ( holds an array of ids) and a function to add id, that will be used for two systems. |
|
Answer» DUMP function is used to print the content of the object For eg: class PERSON { let name: String let cars: [String]? init(name:String, cars: [String]?) { self.name = name self.cars = cars } }let allPerson = [Person(name: "P1", cars: ["P1_C1", "P1_C2"]), Person(name: "P2", cars: ["P2_C1", "P2_C2"])] Output: ▿ 2 elements ▿ App.Person #0 - name: "P1" ▿ cars: Optional(["P1_C1", "P1_C2"]) ▿ some: 2 elements - "P1_C1" - "P1_C2" ▿ App.Person #1 - name: "P2" ▿ cars: Optional(["P2_C1", "P2_C2"]) ▿ some: 2 elements - "P2_C1" - "P2_C2" //As seen, dump() OUTPUTS the whole class hierarchy, while print() SIMPLY outputs the class name. |
|