How do i prevent duplicates in RealmSwift List?

It depends on what kind of data coming from the server. If entire playlist data always come (you can always replace existing playlist data), you can just remove the list to empty, then append them.

realm.write {
    user.playlists.removeAll() // empty playlists before adding

    for playlistData in allPlaylistData {
        let playlist = Playlist()
        ...
        user.playlists.append(playlist)
    }
}

If differential data coming from the server (also some are duplicated), you have to check whether the data already exists.

realm.write {
    for playlistData in allPlaylistData {
        let playlist = Playlist()
        ...

        realm.add(playlist, update: true) // Must add to Realm before check

        guard let index = user.playlists.indexOf(playlist) else {
            // Nothing to do if exists
            continue
        }
        user.playlists.append(playlist)
    }
}