A collection for my journey to learn Swift programming language, a powerful and intuitive programming language for macOS, iOS, watchOS, tvOS and beyond.
Visit Swift official website: Swift
Visit SwiftUI website: SwiftUI
SwiftUI is a modern way to declare user interfaces for any Apple platform. Create beautiful, dynamic apps faster than ever before.
SwiftUI is an innovative new way to build user interfaces across all Apple platforms, so you can create better apps with less code. With a declarative Swift syntax that’s easy to read and natural to write, SwiftUI works seamlessly with new Xcode design tools to keep your code and design perfectly in sync. Automatic support for Dynamic Type, Dark Mode, localization, and accessibility means your first line of SwiftUI code is already the most powerful UI code you’ve ever written.
Visit SwiftUI Tutorials from Apple: SwiftUI Tutorials
@Environment(\.colorScheme) var colorScheme
.foregroundColor(colorScheme == .dark ? Color.black : Color.white)
import SwiftUI
// Using this to provide .lightContent status bar style
class HostingController<T: View>: UIHostingController<T> {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
import SwiftUI
prefix operator ⋮
prefix func ⋮(hex:UInt32) -> Color {
return Color(hex)
}
extension Color {
init(_ hex: UInt32, opacity:Double = 1.0) {
let red = Double((hex & 0xff0000) >> 16) / 255.0
let green = Double((hex & 0xff00) >> 8) / 255.0
let blue = Double((hex & 0xff) >> 0) / 255.0
self.init(.sRGB, red: red, green: green, blue: blue, opacity: opacity)
}
}
let hexColor:(UInt32) -> (Color) = {
return Color($0)
}
Use: .foregroundColor(Color(0x111111))
ScrollView(UIScreen.main.bounds.height < 750 ? .vertical : .init(), showsIndicators: false) { ... }
- Take a design-first approach
- Effortlessly share model code
- Be judicious when sharing new code
- Learn once, apply anywhere
- Keyboard shortcuts
- Provide useful information
- Offer intuitive actions
- Deliver at the right time
3 keypoints:
- 10-foot experience
- Large screen
- Long viewing distance
- Extended periods of use
- Multiple viewers at the same time
- Focus and the Siri Remote
- Entire interface must support focus
- SwiftUI supports focus by default
- Streamlined navigation
- TabbedView
Once you've learned the basics of SwiftUI, you've learned what you need to know to use SwiftUI anywhere. You can use the same SwiftUI skills for making an iOS app as you would for making an app on watchOS, tvOS or macOS. We'll cover the basics, and then dig into more detail about how SwiftUI can help you make changes to your app on every Apple device. Hear about design principles for each platform and learn about how much code you can share across platforms.
Copyright 2020 Luan Nguyen
Licensed under the MIT License