The Sheriff of Ayr was historically (from 1221) the royal official responsible for enforcing law and order in Ayr, Scotland and bringing criminals to justice. Sundrum Castle was used by the sheriff from the 14th century, and Loudoun Castle from the 16th century. Prior to 1748 most sheriffdoms were held on a hereditary basis. From that date, following the Jacobite uprising of 1745, the hereditary sheriffs were replaced by salaried sheriff-deputes, qualified advocates who were members of the Scottish Bar.