SuperRecord icon indicating copy to clipboard operation
SuperRecord copied to clipboard

Use Generics in NSManagedObject Extension

Open PGLongo opened this issue 9 years ago • 2 comments

I think that we could change NSManagedObject extension using generics.

For example:

Now

func createNewEntity(context:) -> NSManagedObject {}
...
let pokemon = Pokemon.createNewEntity() as! Pokemon

After

class func createNewEntity <T> (context:) ->  T {}
...
let pokemon : Pokemon = Pokemon.createNewEntity()

In my opinion is more secure because you receive a compile error if the type is not explicit!

PGLongo avatar Oct 23 '15 16:10 PGLongo

but still requires a type annotation right?

whats the interop with Obj-C like? id ?

michaelarmstrong avatar Oct 23 '15 16:10 michaelarmstrong

Obj-c with Xcode 7 has Generics, but I have never tried

PGLongo avatar Oct 23 '15 17:10 PGLongo