title: macOS App: Don't Let Sync Changes Overwrite User Typing
body: <p><em>Xcode 10.1, Swift 4.2, Realm 3.12 (database)</em></p>
  
  <p>I have a Mac app where multiple users collaborate and the data syncs across multiple devices. So data is always changing.</p>
  
  <p>Throughout the app, I write code that updates the UI when a sync occurs in the background. A problem I keep running into is that when a user is typing in an <code>NSTextField</code>, a sync will happen (from another user's changes) and the <code>NSTextField</code> where they are typing will suddenly revert to the new sync value, and the user will lose what they typed.</p>
  
  <p>Here is a demo Mac app I put together that simulates the problem. If you start typing in the field, every 10 seconds the field updates: <a href="https://d.pr/f/8iXjqx" rel="nofollow noreferrer">https://d.pr/f/8iXjqx</a></p>
  
  <p>I'm wondering what strategies other Mac devs have used to avoid these collisions. </p>
  
  <p>Is there a way to tell an <code>NSTextField</code> to not update if there is a cursor present in it? Do I have to save the value to my local database with every keystroke and then somehow do a merge when a sync happens?</p>