Hi,
I have an NSOutlineView, and each cell within that has an NSCollectionView (a horizontal one), setup using autolayout with the 'height' of the collectionView driving the height of the OutlineView cell. Each item in the collectionView can have a dynamic width, and I use a 'dummy' collectionView to size each item from it's contents, then getting the height of the collectionView and using a 'height constraint' to make each collectionView get the height it needs (and hence the cell have a dynamic height.
It works fine for the most part, but I get this warning multiple times in the console:
"The behavior of the UICollectionViewFlowLayout is not defined because: the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
The relevant UICollectionViewFlowLayout instance is <NSCollectionViewFlowLayout: 0x10e3b7f80>, and it is attached to <MacTagsCustomCollectionView: 0x10e3b7840>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger."
I've tried Googling this, but I can't find a good explanation for this issue. Also, I'm not sure why it references 'UICollectionViewFlowLayout' when it's an AppKit app and uses NSCollectionView. Also, setting the 'UICollectionViewFlowLayoutBreakForInvalidSizes' symbolic breakpoint doesn't help since it never gets triggered.
Here is some code from my outlineView's viewForTableColumn, where I get the height of the collectionView and hence the height of the cell:
result = [outlineView makeViewWithIdentifier:@"DataWithTags" owner:self];
if (result.tagListCollectionView.delegate == nil) {
result.tagListCollectionView.delegate = self;
result.tagListCollectionView.dataSource = self;
result.tagsCollectionViewScrollView.automaticallyAdjustsContentInsets = NO;
result.tagListCollectionView
NSNib *cellNib = [[NSNib alloc] initWithNibNamed:@"MacTagsForPersonItem" bundle:nil];
[result.tagListCollectionView registerNib: cellNib forItemWithIdentifier:@"PersonTagsCollectionViewItemID"];
if (self.tagsSizingItem == nil) {
NSArray *topLevelObjects;
[cellNib instantiateWithOwner:self.tagsSizingItem topLevelObjects: &topLevelObjects];
for (id topLevelObject in topLevelObjects) {
if ([topLevelObject isKindOfClass:[MacPersonTagsCollectionViewItem class]]) {
self.tagsSizingItem = topLevelObject;
break;
}
}
}
result.tagListCollectionView.backgroundColors = @[[NSColor clearColor]];
result.tagListCollectionView.enclosingScrollView.backgroundColor = [NSColor clearColor];
result.tagsCollectionViewScrollView.verticalScroller.hidden = YES;
}
result.tagListCollectionView.tagsPerson = person;
[result.tagListCollectionView reloadData];
result.frame = outlineView.bounds;
[result layoutSubtreeIfNeeded];
[result.tagListCollectionView layoutSubtreeIfNeeded];
if (person.tagsCacheHeight == 0) {
	 person.tagsCacheHeight = result.tagListCollectionView.collectionViewLayout.collectionViewContentSize.height;
}
result.collectionViewHeightConstraint.constant = person.tagsCacheHeight;
Anyone with any idea on how to overcome this? I feel that it's responsible for some layout issues that I'm having in the view.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I want to add a NSDatePicker in the sidebar of my app, to help select a date , or a range of dates. I could use the standard NSDatePicker, but it only seems to come in a single size, and doesn't seem to be resizable. I've dropped the NSDatePicker component into a xib file, and added auto-layout constraints, but they don't seem to work. Is there a way to make them respond to auto-layout and be resizable? Or should I be looking for 3rd-party frameworks to integrate with (if so, any recommendations)?
Hi,
In my Core Data schema, I have a 'transformable' attribute in an entity, which is using a custom NSValueTransformer, the purpose of which is to convert a UIImage into NSData with some compression (basically to save a small thumbnail from the image). From this attribute, I had recently started getting these warnings about using NSKeyedUnarchiveFromData:
'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
So I read about this, and figured I'd need to change the NSValueTransformer to using NSSecureUnarchiveFromDataTransformer ... but after making the changes (as best as I understood them) I can't get it to work, and now the app crashes when the attribute is accessed.
This is the existing NSValueTransformer that I was using:
@interface ImageToDataTransformer : NSValueTransformer {
}
@implementation ImageToDataTransformer (BOOL)allowsReverseTransformation {
return YES;
}
(Class)transformedValueClass {
return [NSData class];
}
(id)transformedValue:(id)value {
// for our smaller views this uses much less data and makes for faster syncing
NSData *compressedData = UIImageJPEGRepresentation(value, 0.2);
return compressedData;
}
(id)reverseTransformedValue:(id)value {
UIImage *uiImage = [[UIImage alloc] initWithData:value];
NSData *data = (NSData *) value;
//NSLog(@"reverseTransformedValue: image size: %@", [NSByteCountFormatter stringFromByteCount:data.length countStyle:NSByteCountFormatterCountStyleFile]);
return uiImage;
}
So I changed it to subclass from NSSecureUnarchiveFromDataTransformer instead, and added the following to the implementation:
(NSArrayClass *)allowedTopLevelClasses {
return @[[ImageToDataTransformer class]];
}
(void)setValueTransformer:(nullable NSValueTransformer *)transformer forName:(NSValueTransformerName)name {
NSLog(@"ImageToDataTransfer: calling setValueTransformer");
[NSValueTransformer setValueTransformer:transformer forName:name];
}
(NSArrayNSValueTransformerName *)valueTransformerNames {
return @[@"ImageToDataTransformerName"];
}
Before the Core Data persistent store is accessed, I 'register' the transformer:
[ImageToDataTransformer setValueTransformer: [[ImageToDataTransformer alloc] init] forName:@"ImageToDataTransformerName"];
Now the app crashes when the image is read:
[__NSCFData _rasterizedImage]: unrecognized selector sent to instance 0x7ff53c108800
If I change the transformer back to NSValueTransformer, it works fine. So I'm not sure if I'm missing something from the implementation, or I have misunderstood the premise of 'NSSecureUnarchiveFromDataTransformer'. Would love to know what I can do to fix this.
Hi,
I've been working with Core Data for a number of years, and I remember that when I needed to add attributes or entities to the data model, I had to first create a new model version, then add the new attributes/entities, and then use the "lightweight migration' flag when adding the NSPersistentStore to the NSPersistentStoreCoordinator. If it didn't add the new model version, the app would crash.
I've tried adding something to my data model now after a few years, without adding a new model version in Xcode. And right now, it seems to work fine. I can read/write to the new attribute that I added to an entity, and nothing crashed. I tried this on the simulator, as well as on my device.
Did something change at some point, where adding a new model version isn't a requirement for using lightweight migration? Or am I missing something? Why isn't it crashing anymore (and will it crash if I change my model without adding a new model version and ship it to production)?
Thanks.
I am adding a small SwiftUI view to my NSTableViewCell, using NSHostingView. Occasionally (randomly) I get this crash in the debugger, but I don't understand what it means:
#0 0x00007fff4309ace6 in AG::data::table::grow_region() ()
#1 0x00007fff4309b155 in AG::data::table::alloc_page(AG::data::zone&, unsigned int) ()
#2 0x00007fff4309b430 in AG::data::zone::alloc_slow(unsigned int, unsigned int) ()
#3 0x00007fff430a1bad in AG::Graph::add_attribute(AG::Subgraph&, unsigned int, void const*, void const*) ()
#4 0x00007fff430b87fe in Attribute.initτ_0_0(body:value:flags:update:) ()
#5 0x00007fff42e8da29 in GraphHost.Data.init() ()
#6 0x00007fff4273e532 in ViewGraph.initτ_0_0(rootViewType:requestedOutputs:) ()
#7 0x00007fff4273e3be in ViewGraph.__allocating_initτ_0_0(rootViewType:requestedOutputs:) ()
#8 0x00007fff42d795d6 in NSHostingView.init(rootView:) ()
#9 0x00007fff42d785dd in NSHostingView.__allocating_init(rootView:) ()
#10 0x00000001036494ff in ContactsCountIconsInterface.makeContactsCountView() at /Users/z/Documents/Git/branches/SimpleList/Mac/ContactsCountIconsInterface.swift:23
#11 0x0000000103649558 in @objc ContactsCountIconsInterface.makeContactsCountView() ()
#12 0x000000010347ed1a in -[ContactDataCellView setupIconsCountViewWithCountForLogsCount:todosCount:filesCount:] at /Users/z/Documents/ContactsJournalGit/branches/SimpleList/ContactDataCellView.m:40
#13 0x0000000103445f88 in -[MacContactsViewController outlineView:viewForTableColumn:item:] at /Users/z/Documents/ContactsJournalGit/branches/SimpleList/Mac/MacContactsViewController.m:745
#14 0x00007fff22dde8b5 in -[NSTableView(NSTableViewViewBased) makeViewForTableColumn:row:] ()
#15 0x00007fff22dddf03 in -[NSTableRowData _addViewToRowView:atColumn:row:] ()
#16 0x00007fff22dddc38 in -[NSTableRowData _addViewsToRowView:atRow:] ()
#17 0x00007fff22ddbf41 in -[NSTableRowData _initializeRowView:atRow:] ()
#18 0x00007fff22dda3d3 in -[NSTableRowData _preparedRowViewForRow:storageHandler:] ()
#19 0x00007fff22dda21e in -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] ()
#20 0x00007fff22dda034 in -[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] ()
#21 0x00007fff22dd8f2a in -[NSTableRowData _updateVisibleRowEntries] ()
#22 0x00007fff236dedbb in __59-[NSTableRowData _automaticRowHeightsUpdateVisibleRowViews]_block_invoke.1371 ()
#23 0x00007fff22fff21b in -[NSTableRowData _keepTopRowStable:andDoWorkUntilDone:] ()
#24 0x00007fff22ffeff8 in -[NSTableRowData _automaticRowHeightsUpdateVisibleRowViews] ()
#25 0x00007fff22dd8873 in -[NSTableRowData updateVisibleRowViews] ()
#26 0x00007fff22f089da in -[NSTableRowData prepareContentInRect:] ()
#27 0x00007fff22f0896f in -[NSTableView prepareContentInRect:] ()
#28 0x00007fff22f086d6 in __38-[NSView _pullInExtraTilesForOverdraw]_block_invoke ()
#29 0x00007fff22f07fd2 in -[NSView _performWorkOnTilesFromRect:renderedContentRect:maximumRect:scrollVelocity:handler:] ()
#30 0x00007fff22f07767 in -[NSView _pullInExtraTilesForOverdraw] ()
#31 0x00007fff22f073ef in -[NSView _doIdlePrefetch] ()
Can anyone comment on how to decipher this crash?
Hi,
I am using the (deprecated) UILocalNotification class in my app right now, because it fulfills a need that the UserNotification framework doesn't fulfill even 5 years after it was introduced. In my app, users can setup 'reminders' for different tasks, and those could be one-off tasks, or repeating tasks that start from a particular date/time. The UserNotifications system doesn't work with the latter requirement; it doesn't allow for you to setup a repeating alert which starts at a specific date/time. You can either setup a one-off alert in the future, or you can setup a repeating alert which starts as soon you set it up. As an example, I want to be reminded to call a friend of mine every week, from July 10th onward ... with the UserNotification framework, setting a 'repeat' will mean it'll fire an alert every week, starting from today.
So what's the best way to build a solution to this? Is there a way to 'intercept' the alert before it's shown (if it's before the date we want it to start firing)? Should I be looking at some 3rd-party services to do this remotely?
Thanks!
Hi,
I want to install macOS Catalina on a partition on my computer's hard drive to test and fix some bugs for my Mac app. I can't seem to find a simple way to download the installer. I found a link to the Catalina page on the Mac App Store through some other website, but when I try to download it, I get an error saying "This copy of the macOS Catalina installer application is too old to be opened on this version of macOS".
I've checked the Downloads page from the developer page, and it's not listed there either. What gives? Shouldn't be easier to test Mac apps on older versions?
FWIW I'm trying this on a MacBook Pro 2016.
Hi,
I haven't been able to add some basic SiriKit actions to my macOS app in macOS Monterey. To test this out, I created a new project, made it a macOS app with Storyboard. Then I added an intents definition file, and added a basic intent, with no inputs/outputs. I added the intent name to "Supported Intents" in the target "General" configuration.
Now when I build and run the app, the shortcut doesn't show up in the Apple Shortcuts app. I've tried looking for the "Siri" capability in "Signing & Capabilities" and it's not listed there (compared to a new iOS app where it would be).
I'm not sure what I'm missing here. Would love some help.
I'm using Xcode 13.1 on macOS Monterey RC.
I am building a widget for my (AppKit) Mac app, and one thing I can't figure out is how to detect when a Link is pressed in the widget to open the parent app. It just opens the parent app but I can't get any information about the URL that was passed in. With iOS, it's easy to detect, from the AppDelegate method:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
I can't find anything equivalent on macOS. Can someone point me to the right place?
Hi,
I have an existing AppKit-based Mac app that I have been working on for a few years. For a new feature, I wanted to have the app opened by a different app, so I setup the URL scheme under CFBundleURLTypes in my Info.plist, and adopted this delegate callback:
- (void)application: (NSApplication *)application openURLs:(nonnull NSArray<NSURL *> *)urls
Now when I invoke the URL from the 2nd app, it opens my app correctly, BUT this delegate method isn't called. What's interesting is that if I make a totally new app with a URL scheme and adopt this delegate method, it gets called without a problem!
SO what about my original project could be responsible for this 'opensURLs' method to not be called? I've been searching for a solution for a couple of days without any luck. The macOS app's target has a Deployment Target of 10.15 and I'm running this on macOS12.0 with Xcode 13.
Hi,
I am trying to build a Mail 'action' extension, and want to access the email body and parse it for specific content. Not sure how to go about converting the 'rawData' that comes in the MEMessage into something that I can read.
Here's how I access the rawData property:
func decideAction(for message: MEMessage, completionHandler: @escaping (MEMessageActionDecision?) -> Void) {
var action: MEMessageActionDecision? = nil
if let messageData = message.rawData {
print("messageData = \(messageData)")
// what to do here??
} else {
action = MEMessageActionDecision.invokeAgainWithBody
}
return action
}
The documentation just says this is 'unprocessed data':
The content is available after MailKit downloads the message. MailKit provides the content as unprocessed data. For details about the format of the data, see RFC 2822.
But I'm not sure what I'm supposed to do to go about converting the unprocessed 'data' into something that is accessible and useful to my app.
Let me know if you have any thoughts or recommendations
Hi,
I have a paid app in the Mac App Store, and I want to verify that the user purchased the app legitimately. Does the StoreKit2 framework have an easy way to determine this? From the documentation I've seen, I believe the 'Transaction.currentEntitlements' call will only return transactions for IAP and subscriptions. I would assume that 'Transaction.all' would work, but when I run the app (with Xcode debugger attached) I get no results.
What's the best way to test this out for an app that's going to be paid-up-front?
Hi,
I am working on a widget for my existing Mac app. The problem I am running into is that when I add a Link from the widget to the main app, the method 'openURLs' isn't called at all:
- (void) application: (NSApplication *)application openURLs:(NSArray<NSURL *> *)urls
So I'm not able to direct the app on how to best handle the widget tap.
I'm trying to work around that by trying to detect if a Link was selected. Something like this could work
Link("Test", destination: URL(string: "https://duckduckgo.com")!)
.environment(\.openURL, OpenURLAction { url in
print("---> testing link actioned")
return .systemAction
})
When I add this to the main app, it works fine. But when I add something like this to the widget, the completion handler isn't called (supposedly).
Can someone confirm if this was supposed to work inside a widget? Or is it only something that works from the main app?
Hi,
I have a paid app available through the Mac App Store, and when the user opens the app, I want to verify that the transaction of the payment is valid. I would have assumed that in StoreKit2, the 'Transaction.all' would work, but when I tested this, it shows 0 transactions for all users.
This is what I'm testing:
for await result in Transaction.all {
guard case .verified(let transaction) = result else { continue }
print("verified product = \(transaction.productID)")
// send to analytics
}
But nothing gets observed in the analytics.
Does the StoreKit2 framework have an easy way to determine transactions that are made for paid-up-front apps?
Hi,
I want to work with some of the new iOS16 APIs while maintaining backward compatibility with iOS15 as well as Xcode 13. I'm running into a problem here that I can't seem to store the new iOS16 API as a property of an existing class.
For e.g. I'm interested in using the new DataScannerViewController and want to store it as a property so I can reference it when scanning. If I declare it in my ViewController:
var dataScanner: DataScannerViewController?
it won't compile with Xcode13. I can't seem to also mark this with @available or #available(iOS 16) either:
if #available(iOS 16, *) {
var dataScanner: DataScannerViewController?
}
What's the best way to handle this? In Objective-C, we could use __IPHONE_OS_VERSION_MIN_REQUIRED or something to that effect to avoid this problem, but I'm not sure what the best Swift solution is.