Skip to content

Instantly share code, notes, and snippets.

@bsneed
Created March 30, 2015 20:07
Show Gist options
  • Select an option

  • Save bsneed/88dc37b724d52bb09291 to your computer and use it in GitHub Desktop.

Select an option

Save bsneed/88dc37b724d52bb09291 to your computer and use it in GitHub Desktop.
reflection tests
//
// THGDataMapTests.swift
// THGDataMapTests
//
// Created by Brandon Sneed on 3/28/15.
// Copyright (c) 2015 TheHolyGrail. All rights reserved.
//
import UIKit
import XCTest
//: Playground - noun: a place where people can play
import UIKit
protocol Model {
func newInstance() -> Self
//func isValidModel() -> Bool
}
@objc
protocol ObjcModel {
func newInstance() -> Self
}
struct MySubObject {
var string: String?
}
struct MyObject {
var string: String?
var number: NSNumber
var uint: UInt
var int: Int
var null: NSNull
var subObject: MySubObject
}
struct MyOptionalObject: Model {
var string: String?
var uint: UInt?
var number: NSNumber?
var array1: Array<String>?
var array2: [String]?
var object: MySubObject?
func newInstance() -> MyOptionalObject {
return MyOptionalObject()
}
}
class THGDataMapTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
//XCTAssert(true, "Pass")
var asubObject = MySubObject(string: "sub-astring")
var object = MyObject(string: "astring", number: 12.3, uint: 1, int: -1, null: NSNull(), subObject: asubObject)
var optional = MyOptionalObject()
optional.string = "astring"
var s = "blah"
let members = reflect(optional)
println()
for i in 0..<members.count {
let (name, types) = members[i]
println("name = \(name), types = \(types.valueType), value = \(types.value)")
if types.value is Model {
let newInstance = (types.value as! Model).newInstance()
}
}
println()
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
// Put the code you want to measure the time of here.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment