When the plaintiff is entitled to damages for withholding or using or injuring the plaintiff's property, the defendant may set off the value of any permanent improvements made thereon to the extent of the damages, unless the defendant prefers to take advantage of the law for the benefit of occupying claimants.
Iowa Code § 646.20
Occupying claimants, chapter 560