ActiveRecord.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 findBy(
  29. func all() -> Array<String> {
  30. return []
  31. }
  32. func commit(error: NSErrorPointer) -> Bool {
  33. //TODO commit changes to DB.
  34. return false
  35. }
  36. }
  37. // An example model class.
  38. class Person: SwifterActiveRecord {
  39. var firstName: String?
  40. var lastName: String?
  41. var age: UInt?
  42. }