How to use background in iOS
Issue #631
beginBackgroundTask
When your app moves to the background, the system …
Discover all the tech
Issue #631
When your app moves to the background, the system …
Issue #630
For SwiftUI app using NSPopover, to show context popover menu, we can ask for windows array, get the _NSPopoverWindow and calculate the position. Note that origin of macOS screen is bottom left
(lldb) po NSApp.windows
▿ 2 elements
- 0 : …Issue #629
Use Picker with SegmentedPickerStyle.
Picker(selection: $preferenceManager.preference.display, label: EmptyView()) {
Image("grid")
.resizable()
.padding()
.tag(0)
Image("list")
.resizable …Issue #628
extension XCUIElementQuery: Sequence {
public typealias Iterator = AnyIterator<XCUIElement>
public func makeIterator() -> Iterator {
var index = UInt(0)
return AnyIterator {
guard index < …Issue #627
Algorithm from https://www.w3.org/WAI/ER/WD-AERT/#color-contrast
extension NSColor {
var isLight: Bool {
guard
let components = cgColor.components,
components.count >= 3
else { return false } …Issue #626
SwiftUI does not trigger onAppear and onDisappear like we expect. We can use NSView to trigger
import SwiftUI
struct AppearAware: NSViewRepresentable {
var onAppear: () -> Void
func makeNSView(context: …Issue #625
For some strange reasons, content inside ForEach does not update with changes in Core Data NSManagedObject. The workaround is to introduce salt, like UUID just to make state change
struct NoteRow: View {
let note: Note
let id: UUID …Issue #624
By default the approaches above grant you access while the app remains open. When you quit the app, any folder access you had is lost.
To gain persistent access to a folder even on subsequent launches, we’ll have to take advantage of a …
Issue #623
Listen to context changes notification and change SwiftUI View state
let changes = [NSDeletedObjectsKey: ids]
NSManagedObjectContext.mergeChanges(
fromRemoteContextSave: changes,
into: [context]
)
try context.save()
struct …Issue #622
Read Implementing Batch Deletes
If the entities that are being deleted are not loaded into memory, there is no need to update your application after the NSBatchDeleteRequest has been executed. However, if you are deleting objects in the …
Issue #621
Make subview that accepts FetchRequest. Trigger search by setting property
struct SideView: View {
@Environment(\.managedObjectContext)
var context
@State var search: Search?
var body: some View {
VStack(alignment …Issue #620
For NSWindow having levelother than .normal, need to override key and main property to allow TextField to be focusable
class FocusWindow: NSWindow {
override var canBecomeKey: Bool { true }
override var canBecomeMain: Bool { …Issue #618
Create custom Binding
List {
ForEach(self.items) { (item: item) in
ItemRowView(item: item)
.popover(isPresented: self.makeIsPresented(item: item)) {
ItemDetailView(item: item)
}
}
} …Issue #617
On macOS 11, we can use .help modifier to add tooltip
Button()
.help("Click here to open settings")
If you support macOS 10.15, then create empty NSView and use as overlay. Need to updateNSView in case we toggle the state of …
Issue #615
List {
ForEach(books) { (book: Book) in
BookRow(book: book)
}
}
.listStyle(SidebarListStyle())
Issue #614
struct MyTabView: View {
@EnvironmentObject
var preferenceManager: PreferenceManager
var body: some View {
VOrH(isVertical: preferenceManager.preference.position.isVertical) {
OneTabView(image: …Issue #613
struct VOrH<Content>: View where Content: View {
let isVertical: Bool
let content: () -> Content
init(isVertical: Bool, @ViewBuilder content: @escaping () -> Content) {
self.isVertical = isVertical …Issue #612
Use runModal
This method runs a modal event loop for the specified window synchronously. It displays the specified window, makes it key, starts the run loop, and processes events for that window. (You do not need to show the window …
Issue #611
enum WindowPosition: String, CaseIterable {
case left
case top
case bottom
case right
}
Picker(selection: $preference.position, label: Text("Position")) {
ForEach(WindowPosition.allCases, id: \.self) { …I’m a thinker and storyteller with a passion for exploring the intersection of creativity and technology
🧑💻 I love crafting high quality and useful apps
🔥 I love open source. My GitHub open source has 2.3k followers with packages that are integrated by 45k+ apps and over 3.4m+ downloads on CocoaPods.
✍️ I write here on my blog and on Medium, which has over 2.7k+ followers with tons of articles and 90k+ monthly views.
🖥 Follow me for sharings about Swift, SwiftUI, iOS and macOS development.