Preheat oven to 350°F (175°C). Grease and flour a 9×13-inch baking pan.
In a medium bowl, whisk together flour, baking soda, salt, and cinnamon. Set aside.
In a large mixing bowl, beat softened butter and sugar together until light and fluffy.
Mix in eggs one at a time, followed by vanilla extract.
Gradually add the dry mixture to the wet mixture, stirring until just combined.
Gently fold in grated apples and walnuts (if using).
Pour the batter into the prepared pan and bake for 30–35 minutes, or until a toothpick inserted in the center comes out clean.
Allow the cake to cool completely on a wire rack.
Beat cream cheese and butter until smooth. Gradually add powdered sugar and vanilla, mixing until creamy and spreadable.
Spread the frosting evenly over the cooled cake. Slice and enjoy.