converted core data example to Swift, except for managed object category