jeudi 12 février 2015

ActiveRecord like reflection in swift

I was wondering how to accomplish an active record like (not with core data, but with rest, but this part I don't think will be an issue).


The issue its that don't understand well the reflection in swift, and my goal its to have a base class called Collection like (just prototype not really working code here):



public class Collection
{
public var Id: String
public static func Name () -> String
{
// accomplished but not with static method
}

public static func Find () -> [ChildClass] // the child class how can I obtain dynamically?
{
// restful things
return [ChildClass, ChildClass, ...] // rest result maped from json
}

public static func FindById (id : String) {}

// also Save && Delete methods
}


This kind of things I accomplish in c# with WSD-Data exactly in this class


So the usage maybe will:



public class User : Collection
{
public var FirstName: String
public var LastName: String
}


or c# like (dunno if this can be done in swift)



public class User : Collection<User> // we pass user as reference class c# like
{
public var FirstName: String
public var LastName: String
}


I hear also other alternatives to get this done, because don't know so well swift and the way that things are done with it.






Aucun commentaire:

Enregistrer un commentaire