Chapter7 Time-ato application

The application Time-ato why not use SwiftUI?

See section 7.3 called “Why AppKit?”

I’m a macOS programmer for many years. I’m happy to see the first book focus on macOS using SwiftUI.
There are a lot of concepts difference between macOS and iOS.

  • manipulate Window
  • menu bar
  • tool bar
  • responder chain
  • mouse event
  • table view
  • outline view
    .
    .
    .

How long can I continue access this book when you release a new version, If i buy it?
Do you have plan adding more topics in this book?
thanks

I haven’t thought about new topics yet, but I hope to keep the book up to date with new versions of macOS. If Apple adds new features, then I will certainly think about putting them in the book.

As regards on-going access, that depends how you bought the book. I suggest contacting support at raywenderlich.com.

1 Like

Hi,
THANKS YOU for a fabulous book! I am really enjoying it!

I have an M1 MBP in case this is a hardware generated bug.

I am getting a crash “Thread 1: Fatal error: Range requires lowerBound <= upperBound” in the clearTasksFromMenu method at the for loop.

I checked the code and all seem right.

Any ideas?
Thanks,
Blessings,
–Mark

Ah, Referencing Outlets! YOu are my bane!

I connected the Main menu NOT the Menu! Doh!

Back to this excellent book!

Blessings,
–Mark

Great work finding the problem. It’s easy to get confused with the way you have menus within menu items with menus.

And thank you. I hope you enjoy the rest of the book.

Hi again,

I am trying to change the statusItem?.button?.image = NSImage to a different SF Symbol. When the app launches, it briefly shows the icon I have chosen and then reverts to the systemName timer icon.

I can’t seem to find the place in the code that makes this change. Any ideas?

I am certainly enjoying this book, finishing up chapter 13 now. A brilliant resource! Thank you!

Blessings,
–Mark

Hi Mark,

In TaskManagerExt.swift, there’s a computed property called menuTitleAndIcon which sets the menu icon as well as its text. Change the icon name returned by that to use a different one.

Sarah

Thanks so much.

I kept looking at the code and I finally remembered the computed variable. I had worked out a solution in updateMenu method and the simple change in the computed variable is so much more elegant.

Thanks so much!
Blessings,
–Mark

1 Like

I also enjoyed this book and many thanks for making it available.

In trying to use Table in MacOS SwiftUI project I have some questions regarding compatibility with the Swift NSTableView architecture:

(1) in NSTableView I would use an array of objects to populate the table view. In this case I can get an index into that array from the selection events. Then I can access that row (or rows) data using just that index value from the object array. However it seems in SwiftUI you can only get the ID value of the selected row(s) and then have to do a search of the entire array to find the entry whose ID field matches the selection(s). This seems somewhat inefficient if it is a large array?

(2) in NSTableView you can also get clicked row index and access row’s data using it. This is useful in cases where you want to do something related to a row of the table without selecting the row directly. Is there any way to accomplish this in SwiftUI?

(3) I can attach context menu to the SwiftUI table and display it using “right” mouse click on a row of the table. When processing a corresponding menu item event how can I determine which row triggered the context menu display? Is it just that you have to select a row first and then use the selected item ID for the context menu events and then assume it is for the selected row?

Hi, great to hear that you are enjoying the book.

I’ll answer your questions as best I can, but I may re-visit them later in the year as the way SwiftUI handles Tables is changing as they become de-coupled from NSTableView.

  1. It appears that only an id property is valid as the selection variable. If you had a large number of data points, maybe using a set or creating a lookup dictionary would help.

  2. SwiftUI much prefers to use data id instead of row index as row index can be changed by so many things. So you’ll just have to start from the selection variable and work from there.

  3. I did some tests here and couldn’t find any way of detecting which row the right-click was on, so yes, I think you’re right and you have to work with the selected row.

Sarah

thanks for the reply! It will be interesting to see how the SwiftUI Table evolves over time.

Regarding question (1) I came up with a simple approach that mostly works:
when generating the data object array, assign the object’s index in the array as its ID field; then the selected item ID can be used directly as the array index to access it, IE array[itemID].

Of course if the table supports sorting then these ID values would have to be reassigned following a change in the sort order. Also if the app supports adding or removing table rows then the indexes could stop working properly. But for simple apps with large table arrays it should be ok

If you know the row order won’t change, then this will work fine. If you add sorting, things will get difficult.