ActiveRecord.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // ActiveRecord.swift
  3. // Swifter
  4. //
  5. // Created by Damian Kolakowski on 13/11/14.
  6. // Copyright (c) 2014 Damian Kołakowski. All rights reserved.
  7. //
  8. import Foundation
  9. struct SwifterActiveRecordField {
  10. let name: String?
  11. }
  12. class SwifterActiveRecord /* Probbaly we will use generics and not follow Ruby's approach based on subclassing. Methods like find() and get() need to return a correct types. */ {
  13. init() {
  14. let properties = listProperties()
  15. // TODO migrate properties scheme to DB scheme.
  16. }
  17. private func listProperties() -> [SwifterActiveRecordField]? {
  18. // Extract public properties so we will know
  19. var results = [SwifterActiveRecordField]()
  20. let classInfoDump = reflect(self)
  21. for var index = 1; index < classInfoDump.count; ++index {
  22. let field = classInfoDump[index]
  23. results.append(SwifterActiveRecordField(name: field.0))
  24. print("\(field.1.valueType)")
  25. }
  26. return results
  27. }
  28. func commit(error: NSErrorPointer) -> Bool {
  29. //TODO commit changes to DB.
  30. return false
  31. }
  32. }
  33. // An example model class.
  34. class Person: SwifterActiveRecord {
  35. var firstName: String?
  36. var lastName: String?
  37. var age: UInt?
  38. }