The story
Long ago, the round pupil at the center of the eye was called its “apple.” Since you guard your eyes above almost anything, the person you held that dear became the apple of your eye. The phrase turns up in Old English in a book linked to King Alfred the Great, around the year 885, which makes it one of the oldest sayings still in use.