website/ios/recipies.md
2025-08-03 16:27:25 +02:00

68 lines
1.1 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
layout: default
title: Recipies
categories: swift
---
```swift
extension UIFont {
var bold: UIFont {
guard let newDescriptor = fontDescriptor.withSymbolicTraits(.traitBold) else {
return self
}
return UIFont(descriptor: newDescriptor, size: pointSize)
}
}
```
```swift
public struct FontStyle: ViewModifier {
let isBold: Bool
private let font: Font
public init(isBold: Bool = false) {
self.isBold = isBold
self.font = self.font.bold
}
public func body(content: Self.Content) -> some View {
content.font(font)
}
}
extension View {
public func fontStyle(isBold: Bool = false) -> some View {
modifier(FontStyle(isBold: isBold))
}
}
```
## Testing
```swift
class ExampleXCTestCase: XCTestCase {
let app = XCUIApplication()
override func tearDown() {
app.terminate()
}
override func tearDownWithError() throws {
app.terminate()
}
}
```
In tests (it has to be called before `app.launch()`)
```swift
launchEnvironment["key"] = "value"
```
in the app:
```swift
ProcessInfo.processInfo.environment["key"]
```