michaelarmstrong / SuperRecord

A small set of utilities to make working with CoreData and Swift a bit easier.
MIT License
366 stars 27 forks source link

Use Generics in NSManagedObject Extension #45

Open PGLongo opened 9 years ago

PGLongo commented 9 years ago

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!

michaelarmstrong commented 9 years ago

but still requires a type annotation right?

whats the interop with Obj-C like? id ?

PGLongo commented 9 years ago

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