Hot answers tagged

5

The conversion function convertedDegreeC2F() handles only four of the nine possible conversions between the three units. In particular, the conversion between identical input/output unit is not handled. Also the function name is misleading because the function is not about conversion from Celsius to Fahrenheit only. The conversion between temperature units ...


2

The names of the measurement units are wrong. Kelvin does not take a degree. It's just K, not °K. Fixing this requires changes to most of the code. It's a waste of computation time to calculate all possible conversions and then only use one of them. You can be lucky that you are converting temperatures and not ancient lengths, of which there are hundreds. ...


2

The role of your ZStack and border rectangle could be replaced with a .background or .overlay modifier on the Sparkline itself - would allow more flexibility in presentation at the point-of-usage.


2

There is a shorter and faster way, using ternary operators. You could use Text("Home").foregroundColor(self.viewRouter.currentView == "home" ? Color.blue: Color.black) instead of { () -> Text in if self.viewRouter.currentView == "home" { return Text("Home").foregroundColor(Color.blue) } else { return ...


2

I need to ask a question when I break up my player into usable components. How should I take this approach The idea is to break a long and not so readable code into smaller parts. Also, each individual part needs to access variables etc. For this you can use a private extension (unless it's in another file, then skip private): struct ContentView: View { ...


1

First there's some low hanging fruit. Perpetual use of self. when not needed. Use of parens when not needed. Inconsistent formatting (sometimes you put a space before the open brace, sometimes you don't. Sometimes you put code after a close brace on the same line, sometimes you don't.) These seem like minor things I'm sure and the compiler doesn't care at ...


1

A few observations: When using Booleans, we would generally not use the == true test, much less the parentheses. E.g. from The Swift Programming Language: The Basics Boolean values are particularly useful when you work with conditional statements such as the if statement: if turnipsAreDelicious { print("Mmm, tasty turnips!") } else { ...


1

Your code is perfectly fine. Just a couple of comments: It is bad-to-impossible to have any internal state in a View. Actually SwiftUI was designed to handle state changes directly in a view. For simple cases you can easily do: struct PageIndicator: View { @State private var currentPage = 0 let numPages: Int = 5 private let spacing: CGFloat = ...


Only top voted, non community-wiki answers of a minimum length are eligible