Post

Replies

Boosts

Views

Activity

Reply to Crash when setting up the content view loaded from a NIB
Hi @fmoraes , well I think you should try to move on autolayout constraints and not use explicit frame width o height. Try for example this arrangement: class MyView: NSView { @IBOutlet var contentView: NSView! init() { super.init(frame: .zero) commonInit() } required init?(coder: NSCoder) { super.init(coder: coder) } private func commonInit() { Bundle.main.loadNibNamed("MyView", owner: self, topLevelObjects: nil) addSubview(contentView) contentView.translatesAutoresizingMaskIntoConstraints = false contentView.topAnchor.constraint(equalTo: topAnchor).isActive = true contentView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true contentView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true contentView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true } } In this way you use a pure auto layout constraints approach, and NSView could be used in this way. override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. let myView = MyView() view.addSubview(myView) myView.translatesAutoresizingMaskIntoConstraints = false myView.widthAnchor.constraint(equalToConstant:84.0).isActive = true myView.heightAnchor.constraint(equalToConstant:49.0).isActive = true myView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true myView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true } Please try to check on nib file if arrangements on outlet are correct. Approach with contentView is really useful if you want to use a compositional approach, but now we have SwiftUI that makes this for us. Attach screenshot with navies layout generate with a label inside your MyView Bye Rob
1w
Reply to UICollectionView Auto cell height problem
Hi @matmacsystem , well it really difficult to understand what's happening, but first at all you should clear what is the layout do you want to obtain. Then, you should, if possible, check the layout of the cell, if all constraints are validated during the execution of the app (check on debug console if some constraints are invalidate). At this point, probably problems could be on custom frame calculation (double check ScreenUtility.getCollectionCellWidthForElement()) . And I will try to reduce calling on setNeedsLayout and layoutIfNeeded. Anyway, if you have a minimal sample project to share, we probably could help. Bye Rob
1w
Reply to SwiftData: Failed to decode a composite attribute
Hi @Xavier-k , well unfortunately in SwiftData (CoreData for old man as me) things are not so simple. What you have done is change on the model that is used to generate the entity relationships based on SwiftData modelling. What I would like to suggest, even if the modification on model is so simple, is to use a migration strategy from old to new model. For example, this is a great article on argument of SwiftData migration https://www.hackingwithswift.com/quick-start/swiftdata/how-to-create-a-complex-migration-using-versionedschema . SwiftData is not simple... Bye Rob
1w
Reply to Data Persistence of AVAssets
Hi @denisdawid , well AVFoundation is a great framework used for audio modeling, but as all Apple frameworks, is not so simple. AVAsset generally are container for single AVAssetTrack, each of this could be a different media type, for example audio, video, video/audio subtitles, and so on. But, if I remember correctly, this objects abstraction are not correlated to media data they represent (that is, load in memory) until you execute an asynchronous data load. Note that from iOS 16 syntax callbacks are more younger, look at this link https://developer.apple.com/documentation/avfoundation/media_assets/loading_media_data_asynchronously Then, what you should try to manage, is this asynchronous loading of media that could optimise the media operations. Use the correct keys should avoid data not necessarily used for your app. Bye Rob
2w
Reply to Binding NSArrayController to an NSMutableArray not working
Hi @that_aint_it_chief , probably it's not clear to me your project, but if you want to use an nsarraycontroller, you should work directly on it, without other data model. For example, you could use this arrangement: @interface ViewController : NSViewController @property IBOutlet ArrayController * tableCities; @end ... @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSString* filePath = @"/tmp/city_test.jpeg"; NSDictionary *obj = @{@"image": [[NSImage alloc] initByReferencingFile:filePath], @"name": @"Milano", @"filePath": filePath}; NSDictionary *obj2 = @{@"image": [[NSImage alloc] initByReferencingFile:filePath], @"name": @"Londra", @"filePath": filePath}; NSDictionary *obj3 = @{@"image": [[NSImage alloc] initByReferencingFile:filePath], @"name": @"Torino", @"filePath": filePath}; [_tableCities addObjects:@[obj, obj2, obj3]]; } @end create an NSArrayController inside the ViewController scene you are developing and link directly to arrangeObjects and model type on inspector tab, as attached screenshots. Bye Rob
Oct ’24
Reply to NavigationStack $path cleared on dealloc?
Hi @Bolsinga , well, I think that you should try to decouple the navigation on single list section. Probably on iPad simulator on regular size class (landscape) , the first and second section are seen on SwiftUI has two different navigation stack, then when you change the section, SwiftUI itself reset the navigation and move on root navigation stack. On compact size class as iPhone portrait mode, you see a reset on section but not moving on , because probably you should change the navigation stack root itself. If you want to maintain the path previously stack navigation, you should use some sort of restore navigation and manage the root navigation itself. try to use the selection variable in your example and build from it the correct path with a binding. Bye Rob
Oct ’24
Reply to iOS 18, XCode 16, SwiftUI display HTML resource file
Hi @asgalon, I think that could not be necessary to wrap WkWebView in none of SwiftUI container view. WkWebView is itself a subclass of UIScrollView UIKit class, then put it inside a SwiftUI ScrollView probably breaks some layout constraints used during UI rendering. But layout should work as expected without use of SwiftUI container view. Obviously, if you want display it on navigation stack or something else, you should. If you don't need to use custom configuration on WKWebView, I suggest to use an UIViewRepresentable as follow struct WebView: UIViewRepresentable { let url: URL func makeUIView(context: Context) -> WKWebView { return WKWebView() } func updateUIView(_ webView: WKWebView, context: Context) { let request = URLRequest(url: url) webView.load(request) } } Bye Rob
Oct ’24
Reply to BGProcessingTaskRequest execute randomly.
Hi @surya_s , well the background tasks management on Apple platform are in some aspects really mysterious, but I think (@DTS Engineer confirm this) that you have no guarantees that background task could execute at specific time, you only specific that you should perform task on background, but from this time, it's a matter of the background task manager how and when execute the task itself. Please note that the earliestBeginDate itself has following description /// The earliest date and time at which to run the task /// /// Specify `nil` for no start delay. /// /// Setting the property indicates that the background task shouldn’t start any /// earlier than this date. However, the system doesn’t guarantee launching the /// task at the specified date, but only that it won’t begin sooner. open var earliestBeginDate: Date? } Bye Rob
Oct ’24
Reply to Opening file from main bundle in Xcode 16
Hi @andsoff , mmm, I will suggest, first at all , to catch the exception, for example in this way do { let content = try String(contentsOfFile: path, encoding: String.Encoding.ascii) } catch let error { print("File read error : \(String(describing: error.localizedDescription))") } Then, I'm no sure that you could decode a csv file as a string. Anyway, should be better working when read file with Data buffer, then I suggest to use something like this let content = try Data(contentsOf: URL(fileURLWithPath: path)) print("File read success: \(content)") If success, content should print read bytes. Bye Rob
Oct ’24
Reply to PHPickerViewController translucency
Hi @wolfson , unfortunately I don't think you should change this behaviour, because PHPickerViewController could not be subclasses, and even if you modify opacity could create problems, see doc for details. https://developer.apple.com/documentation/photokit/phpickerviewcontroller Bye Rob
Oct ’24
Reply to How to observe AVCaptureDevice.DiscoverySession devices property?
Hi @Kusaanko , really interesting question. Try to use this options [.initial, .new] in your addObserver options method: https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions/1413959-initial From the docs it seems that the .initial option behaves las follow: When this option is used withaddObserver(_:forKeyPath:options:context:) a notification will be sent for each indexed object to which the observer is being added. Bye Rob
Oct ’24