TheApplicationFactory / BodyMapPicker

Picker for locations on the human body
MIT License
12 stars 4 forks source link

Restructuring and making the picker class more universal #2

Open GJNilsen opened 8 years ago

GJNilsen commented 8 years ago

My suggestion is to separate the image map itself from the picker. The map parts should be defined as an array of structs like this:

mapData: Struct
  let path: UIBezierPath
  let title: String
  let description: String 

There are pros and cons using this structure Pros:

  1. really little cost to memory,
  2. using value types instead of objects, making it more "swifty", and
  3. the UIBezierPath makes the part look sharp and great regardless of magnification or resolution.
  4. Takes next to nothing in disk space

Cons:

  1. Harder to set up
  2. Vector paths demands the parts to be drawn in a vector based app like Illustrator, and then exported to Swift with an app like PaintCode

I think the vector based images is the proper path to go, since it is resolution and size independent, it will also be more future proof.

So with the images out of the way, the picker could just focus on selecting parts, regardless if it is the whole body, a hand, or some other group of individual parts. Also if someone does not like the design language of the standard body set of parts, it can easily work with any other design right out of the box. Its also important to use only a very limited number of public methods and properties, since the functionality of the picker should be really simple.

ImageMapPicker: UIView public var imageMapArray: [mapData]

the imageMapArray contains an array with mapData Structs. This is set when the view is initialised. We would need a convenience initialiser where we can pass the array of mapData Structs, like this:

init(rect: CGRect, map: [mapData])

If the picker was assigned in IB, the map has to be populated after the view is initialised, thats why the map array needs to be a var instead of let.

To get the selected data back to the view controller, the following protocol should be implemented:

ImageMapPickerDelegate protocol var selectedPart { get }

Here the selectedPart var would contain a mapData Struct of the current selected part.

GJNilsen commented 8 years ago

Im trying to make the naming more "Swifty", so function and variable names will change a lot. Suggestions are appreciated.