Post

Replies

Boosts

Views

Activity

Laying out UIViews for different devices/size classes
I've never had to design a UI to adapt to any possible device, orientation, and account for potential multitasking layouts, and i'm a bit stuck. Traditionally my layout code would go something like: Declare views at the top of view Controller Initialize Views in setupViews function Add constraints in setupConstraints function Override viewWillTransition function to change constraints based on orientation My primary trouble is in the sizing of UI Components. What width and height should I assign to any given, let's say button, if that button is to be displayed on any device in any orientation? On iPad, it would be too small if I lay it out for an iPhone, and the same issue vice-versa. My main question: How do I assign sizes to views so that they look "good" on every device? Secondary question: How do any of you with production app development experience design and layout views to look good in every possible configuration?
0
0
288
Aug ’20
Extend JSONDecoder to allow for models to be serialized differently based on endpoint
I have many models that, depending on the endpoint, or serialized differently. My first attempt had a init(from decoder: Decoder) riddled with nested try catch blocks. I thought a better solution would be to extend JSONDecoder so that when I initialize one, I can specify which endpoint i am pulling from. Then in my models init(from decoder: Decoder) I could have a switch like switch case endpoint1: x = decoder.decode(Int.self, .x) case endpoint2: j = decoder.decode(String.self, .j)The problem I ran into is that the class you have inside the init is a Decoder not a JSONDecoder. I can't figure out a place that, if I extend Decoder and allow myself to specify an endpoint, I could actually specify an endpoint, since JSONDecoder.decode() instantiates it's own Decoder behind the scenes. Thoughts? EXAMPLE: How would you recommend initializing an object from decoder that has say two different variations depending on where you are deserializing it from. For ExampleLets say I get the first book from http://library.com/bookLocations/{id}And the second book from http://library.com/bookInfo/{id}Book: { Author: "James" Title: "JamesBook" LibraryId: "387fh384fh3i09" SectionNumber: "870D" }Book: { Author: "James" Title: "JamesBook" Length: "870" Reviews: "9/10" } What is the best way to handle both cases insideinit(from decoder: Decoder)if I want to use the same model/object for bothstruct Book: Codable { var author: String var title: String var libraryId: String? var sectionNumber: String? var length: String? var reviews: String? }
5
0
883
Dec ’19