# Chapter7 Time-ato application

**URL:** <https://forums.kodeco.com/t/chapter7-time-ato-application/169202>\
**Category:** macOS by Tutorials\
**Created:** [April 18, 2022, 1:57am UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202 "2022-04-18T01:57:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![diuming](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/diuming/32/110937_2.png) [@diuming](https://forums.kodeco.com/u/diuming)\
**Post date:** [April 18, 2022, 1:57am UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/1 "2022-04-18T01:57:54Z")

</div>

The application `Time-ato` why not use SwiftUI?

---

<div class="post-metadata">

**Author:** ![rcritz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcritz/32/111201_2.png) [@rcritz](https://forums.kodeco.com/u/rcritz)\
**Post date:** [April 18, 2022, 2:10am UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/2 "2022-04-18T02:10:31Z")

</div>

See section 7.3 called “Why AppKit?”

---

<div class="post-metadata">

**Author:** ![diuming](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/diuming/32/110937_2.png) [@diuming](https://forums.kodeco.com/u/diuming)\
**Post date:** [April 18, 2022, 2:48am UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/3 "2022-04-18T02:48:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sarah](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sarah/32/111112_2.png) [@sarah](https://forums.kodeco.com/u/sarah)\
**Post date:** [April 18, 2022, 3:06am UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/4 "2022-04-18T03:06:23Z")

</div>

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](http://raywenderlich.com).

---

<div class="post-metadata">

**Author:** ![garageshop](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/garageshop/32/103972_2.png) [@garageshop](https://forums.kodeco.com/u/garageshop)\
**Post date:** [May 1, 2022, 3:43am UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/5 "2022-05-01T03:43:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![garageshop](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/garageshop/32/103972_2.png) [@garageshop](https://forums.kodeco.com/u/garageshop)\
**Post date:** [May 1, 2022, 3:56am UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/6 "2022-05-01T03:56:56Z")

</div>

Ah, Referencing Outlets! YOu are my bane!

I connected the Main menu NOT the Menu! Doh!

Back to this excellent book!

Blessings,  
–Mark

---

<div class="post-metadata">

**Author:** ![sarah](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sarah/32/111112_2.png) [@sarah](https://forums.kodeco.com/u/sarah)\
**Post date:** [May 1, 2022, 4:57am UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/7 "2022-05-01T04:57:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![garageshop](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/garageshop/32/103972_2.png) [@garageshop](https://forums.kodeco.com/u/garageshop)\
**Post date:** [May 5, 2022, 2:43pm UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/8 "2022-05-05T14:43:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sarah](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sarah/32/111112_2.png) [@sarah](https://forums.kodeco.com/u/sarah)\
**Post date:** [May 5, 2022, 10:54pm UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/9 "2022-05-05T22:54:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![garageshop](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/garageshop/32/103972_2.png) [@garageshop](https://forums.kodeco.com/u/garageshop)\
**Post date:** [May 5, 2022, 11:31pm UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/10 "2022-05-05T23:31:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alfansome](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/alfansome/32/102075_2.png) [@alfansome](https://forums.kodeco.com/u/alfansome)\
**Post date:** [June 26, 2022, 9:36pm UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/11 "2022-06-26T21:36:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sarah](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sarah/32/111112_2.png) [@sarah](https://forums.kodeco.com/u/sarah)\
**Post date:** [June 26, 2022, 11:49pm UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/12 "2022-06-26T23:49:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alfansome](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/alfansome/32/102075_2.png) [@alfansome](https://forums.kodeco.com/u/alfansome)\
**Post date:** [June 27, 2022, 1:24am UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/13 "2022-06-27T01:24:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sarah](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sarah/32/111112_2.png) [@sarah](https://forums.kodeco.com/u/sarah)\
**Post date:** [June 28, 2022, 8:15am UTC](https://forums.kodeco.com/t/chapter7-time-ato-application/169202/14 "2022-06-28T08:15:07Z")

</div>

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