Sample code doesn't compile as contextAction has been replaced

Sample code fails to compile with Xcode 14.1 beta 3 (14B5033e) as contextAction has been removed/replaced.

// Compile error: Value of type 'some View' has no member 'contextAction'
#if os(macOS)
.contextAction(forSelectionType: Book.ID.self) { books in

It looks like it has been replaced with contextMenu(forSelectionType:menu) with a slight difference.

Answered by BabyJ in 730807022

What is the actual problem? Which sample code fails to compile?

The old modifier, contextAction(forSelectionType:action:), was removed and its functionality was added to the contextMenu(forSelectionType:menu:primaryAction:) modifier.

It is now used like this:

.contextMenu(forType: Book.ID.self, menu: { _ in }) { books in
    // perform primary action
}


That's just what happens during the beta period: things are added, removed and modified. It's the final version that counts.

Accepted Answer

What is the actual problem? Which sample code fails to compile?

The old modifier, contextAction(forSelectionType:action:), was removed and its functionality was added to the contextMenu(forSelectionType:menu:primaryAction:) modifier.

It is now used like this:

.contextMenu(forType: Book.ID.self, menu: { _ in }) { books in
    // perform primary action
}


That's just what happens during the beta period: things are added, removed and modified. It's the final version that counts.

The sample was updated on 1st March 2023 to fix this and many other problems. If you download the sample again and drag the extracted folder into a Git app like Tower you can see all the changes (screenshot below). The commit message was "Updated the project sourcefor compatibility with macOS 13."

Sample code doesn't compile as contextAction has been replaced
 
 
Q