Here it is: A comprehensive look at `NSItemProvider`: what it does, how it works, and how to use it properly. I want this to be a one-stop-shop reference for anyone using this class in their projects.
NSItemProvider is a key class in iOS and Mac Catalyst, used in everything from Drag and Drop, to Pasteboard, share sheet, and beyond. Understanding how this class works will help you make better apps and gain insight into what the system does for you.
Please read the post, and send me feedback. Share it with your iOS developer friends. Let me know what you think!
https://www.humancode.us/2023/07/08/all-about-nsitemprovider.html
#iOS #iOSDev #macOS #MacCatalyst #apple #Xcode #Swift #ObjectiveC #UIKit #AppKit #programming
#ios #iosdev #macos #maccatalyst #apple #xcode #swift #objectivec #UIKit #AppKit #programming
Did I just spend multiple days on centering toolbar items? Y-yeah. Turns out in an AppKit toolbar, either all items have a label, or none of them does. Setting an empty label leaves the view weirdly positioned.
The code is a big hack: it mutates AppKit-created constraints, finding them by item/attribute pairs. And to make sure the tweak re-runs whenever the toolbar item updates, I had to swizzle a method on the NSToolbarItemViewer private class.
But it works? 😅
Hey #appkit devs out there, you may have heard about how in Sonoma, NSView drawing will no longer clip to bounds by default? And looking at https://developer.apple.com/documentation/macos-release-notes/appkit-release-notes-for-macos-14#NSView , you may have thought to yourself: "No big deal, I'll keep building against an older SDK and these changes won't impact me for years"?
Well, you would be wrong.
Undo/redo code is error-prone. It's even trickier in @Retcon: the app doesn't just restore previous states as-is, it also *merges in* external changes (you can modify your workdir at any time!).
So during integration tests, every single undo state is checked: the test undoes repeatedly, running original asserts each time, then does the same for redo.
To make this effortless to implement, I wrote UndoAssertManager. Boom, bulletproof undo support :)
https://gist.github.com/Cykelero/fa4a8b786ee6d5e18cb88cb3e398f915
I wrote this tiny AppKit extension to make it easier/safer to switch over the response of a NSAlert.
Refer to your buttons explicitly, instead of using alertFirstButtonReturn, where you can break behavior by mistake when later reordering buttons.
(screenshots are before, after, and extension source)
Source: https://gist.github.com/Cykelero/1ff3a0819d52ab1d1904845452b8ddfd
#AppKit #Swift
Ok, it took me a few days, but I have the whole Twitter & Mastodon OAuth flow and account persistence mostly done 😎 Next: the new post window :]
(I don't know yet if I'll actually be able to release this, because it depends on what Lord Elon decides about the API :D) #AppKit #MacDev
Learn how to use DateFormatter to parse, format, and extract components from Dates.
#Swift #Programming #macOS #iOS #UIKit #AppKit
https://www.advancedswift.com/date-formatter-cheatsheet-formulas-swift/
#AppKit #UIKit #iOS #macOS #programming #swift
Hey Mac devs! Does anyone have experience with single-column, AutoLayout-driven NSTableView where cells may contain NSImageViews with possibly large images? Kind of like in Twitter/Mastodon client apps? 🙃
I have a problem that the image views expand the cells beyond the edge of the table view/window. I tried various approaches, but I can't get it to look right in every case.
How can I solve this (without resorting to full manual layout)? https://github.com/mackuba/TableViewCellDemo3
One of those moments in programming when you need to get up from the keyboard and grab a pencil… 🤔 #AppKit #MacDev #NSTableView
Another horrible #macOS #AppKit #bug in #macOS12 and #macOS13
What do you think, will it beep or not?
Let me tell you, it WILL beep.
And the reason is a sloppy and undocumented change made by #Apple in macOS 12, but they completely forgot to actually test and finish properly.
Took us almost a whole day to find and fix it. ARGH.
That is the kind of crap we have to deal with every year, for every new major macOS release.
Things that were stable and worked as documented for 30 years suddenly break. ARGH.
It is so frustrating.
#macos #AppKit #bug #macOS12 #macOS13 #Apple
So … I’ve been trying out AppKit for several weeks now: medium-sized fragments at a time — sometimes just small pieces of code. I am starting to get a clearer view of the advantages and disadvantages of #AppKit vs #swiftui for every time I attempt to design a new dialog window (aka ”screen”). The way I do this is through XIB files. Some people might recommend against it, as it’s an old-school approach to AppKit UI design. I like it much better than storyboards, but both methods work fine.
Do you want to make Mac apps?
Are you having trouble finding learning material?
I put together a list of Mac development materials:
https://www.swiftdevjournal.com/resources-for-learning-mac-development/
There are books, videos, and blogs for both SwiftUI and AppKit along with places to ask questions.
Do you want to make Mac apps?
Are you having trouble finding learning material?
I put together a list of Mac development materials:
https://www.swiftdevjournal.com/resources-for-learning-mac-development/
There are books, videos, and blogs for both SwiftUI and AppKit along with places to ask questions.