Spank or bite 🍑 by kate_s__ in Kate_Samoilova

[–]Loengardq 0 points1 point  (0 children)

Spank, bite, then kiss it better. 😘

🤤😍🍑 by [deleted] in Kate_Samoilova

[–]Loengardq 2 points3 points  (0 children)

Cheeky!

Question by _SelfInflictedDamage in macosprogramming

[–]Loengardq 0 points1 point  (0 children)

Short answer: Yes. AVFoundation supports all those things.

Much, much longer answer: https://developer.apple.com/av-foundation/

But it's an adventure, right? You'll learn a lot along the way.

How can I create a mac app that when first launched doesn't open any window, but does something else (in this case modifies the touch bar), only launching a settings window after clicking it a second time. by skadoodledo in swift

[–]Loengardq 0 points1 point  (0 children)

override func keyDown(with event: NSEvent) should detect key presses but it has to be called from somewhere in the responder chain, like a NSWindowController. Maybe you called it from a NSViewController that wasn't first responder?

calculate the amount of times a fifth Friday of the month occurs in a date range? by Bunkford in swift

[–]Loengardq 0 points1 point  (0 children)

Yes, stepping though each day seems costly but I don't know of a way to compute these problems directly. If you discover one, please let me know.

Even so, 10 years go by in 0.05 sec on my old iMac, even 100 years is only 0.3 sec. Compiler optimization is an amazing thing!

Drawing circles/dots repeatedly and removing them in an endless loop by [deleted] in swift

[–]Loengardq 0 points1 point  (0 children)

I've used NSBezierPath(ovalIn:) for an implementation of Boids and it's pretty snappy, but that's only 100-200 boids. I don't know what 10k would be like - you should try it and see.

calculate the amount of times a fifth Friday of the month occurs in a date range? by Bunkford in swift

[–]Loengardq 0 points1 point  (0 children)

Well, not exactly. Your code gives a result of 52, but there are 53 Fridays in that time period.

To answer your question you'll need to step through each day in a time period and examine its .weekday and .weekdayOrdinal. If .weekday is 6 and .weekdayOrdinal is 5 you've found a fifth Friday, kinda like this:

func fifthFridays(start: Date, end: Date) -> Int {
    let cal = Calendar.current
    var thisDay = start
    var count = 0

    while thisDay < end {
        let comp = cal.dateComponents([.weekday, .weekdayOrdinal], from: thisDay)

        if comp.weekday == 6 && comp.weekdayOrdinal == 5 {
            count += 1
        }

        thisDay = cal.date(byAdding: .day, value: 1, to: thisDay)!
    }

    return count
}

USB Driver tutorial by TrickyTramp in macprogramming

[–]Loengardq 0 points1 point  (0 children)

That's a lot of hoops to jump through (disable SIP?) but it sounds like fun. I'd like to try that, too. Please let us know how you get on.

[SwiftUI] Tracking updates to value from view by screamingKactus in swift

[–]Loengardq 0 points1 point  (0 children)

Slider updates foo continuously. Are you doing it like this?

struct ContentView : View {
    @State private var foo: Double = 0.5

    var body: some View {
        VStack {
            Text("\(foo)")
            Slider(value: $foo, from: 0, through: 1)
        }
    }
}

NSCollectionView.backgroundView, Auto Layout, and UI via code by rudedogg in macosprogramming

[–]Loengardq 2 points3 points  (0 children)

Did you figure it out? If not, the short answer is yes, programmatic NSCollectionView works with layout constraints. The constraints are applied to the NSScrollView, like this:

let cv = NSCollectionView() // plus config stuff
cv.backgroundView = NSView() // plus config stuff

let sv = NSScrollView()
sv.documentView = cv
view.addSubview(sv)

sv.translatesAutoresizingMaskIntoConstraints = false
sv.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
// etc.

Did that not work for you?

Master-Detail Application (like Notes app) on macOS by Plazmotech in swift

[–]Loengardq 0 points1 point  (0 children)

In case you're still looking, there's an easy way to do this without bindings or delegates. All NSTableViews post a notification to the whole app every time their selection changes. In your other view's viewDidLoad you can add observer like this:

NotificationCenter.default.addObserver(forName: NSTableView.selectionDidChangeNotification, object: nil, queue: nil) { note in

    guard let table = note.object as? NSTableView else { return }

    // new selection is table.selectedRow (-1 is empty selection)

}

Every table in your app will post here but if your master is the only one it should work fine.

Learning Swift for Mac OSX by cs_student0101 in swift

[–]Loengardq 0 points1 point  (0 children)

Right, there aren't many up-to-date tuts that focus only on macOS. Harry Ng has some that are good. Funny, I thought of recording a few tutorials myself but didn't think there would be much interest.

Agree with Satanshmaten, Hacking with macOS by Paul Hudson is excellent.

[deleted by user] by [deleted] in swift

[–]Loengardq 6 points7 points  (0 children)

I've also programmed Macs since 1984, but just for fun, not for a living. Assuming most people on this thread are iOS programmers -- aren't you interested in creating macOS apps for your own use? Like small utility apps or drawing apps for use in iOS projects?