A springtime photograph from this past year, during a visit to Anza-Borrego Desert State Park.
The California Native Plant Society’s page for Mammillaria dioica makes mention of this specific growing situation (the latter):
In desert areas it is most often found growing in very rocky areas, sometimes growing out of crevices in granite boulders in the desert-edge canyons.
Fishhook cactus or strawberry cactus is native to southern California and northwestern Mexico. The “strawberry” part of the second name is a reference to the red, ovoid fruit; these apparently taste like a cross between a strawberry and a kiwifruit.