Skip to content

Commit

Permalink
use (T.self as Object.Type).className() instead of T.className()
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Jul 3, 2015
1 parent 6c21559 commit d404ffd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion RealmSwift/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public final class List<T: Object>: ListBase {

/// Creates a `List` that holds objects of type `T`.
public override init() {
super.init(array: RLMArray(objectClassName: T.className()))
// FIXME: use T.className()
super.init(array: RLMArray(objectClassName: (T.self as Object.Type).className()))
}

// MARK: Index Retrieval
Expand Down
3 changes: 2 additions & 1 deletion RealmSwift/Object.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public class Object: RLMObjectBase {
:returns: An `Array` of objects of type `className` which have this object as their value for the `propertyName` property.
*/
public func linkingObjects<T: Object>(type: T.Type, forProperty propertyName: String) -> [T] {
return RLMObjectBaseLinkingObjectsOfClass(self, T.className(), propertyName) as! [T]
// FIXME: use T.className()
return RLMObjectBaseLinkingObjectsOfClass(self, (T.self as Object.Type).className(), propertyName) as! [T]
}


Expand Down
14 changes: 9 additions & 5 deletions RealmSwift/Realm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,12 @@ public final class Realm {
:returns: The created object.
*/
public func create<T: Object>(type: T.Type, value: AnyObject = [:], update: Bool = false) -> T {
if update && schema[T.className()]?.primaryKeyProperty == nil {
throwRealmException("'\(T.className())' does not have a primary key and can not be updated")
// FIXME: use T.className()
let className = (T.self as Object.Type).className()
if update && schema[className]?.primaryKeyProperty == nil {
throwRealmException("'\(className)' does not have a primary key and can not be updated")
}
return unsafeBitCast(RLMCreateObjectInRealmWithValue(rlmRealm, T.className(), value, update), T.self)
return unsafeBitCast(RLMCreateObjectInRealmWithValue(rlmRealm, className, value, update), T.self)
}

// MARK: Deleting objects
Expand Down Expand Up @@ -350,7 +352,8 @@ public final class Realm {
:returns: All objects of the given type in Realm.
*/
public func objects<T: Object>(type: T.Type) -> Results<T> {
return Results<T>(RLMGetObjects(rlmRealm, T.className(), nil))
// FIXME: use T.className()
return Results<T>(RLMGetObjects(rlmRealm, (T.self as Object.Type).className(), nil))
}

/**
Expand All @@ -368,7 +371,8 @@ public final class Realm {
:returns: An object of type `type` or `nil` if an object with the given primary key does not exist.
*/
public func objectForPrimaryKey<T: Object>(type: T.Type, key: AnyObject) -> T? {
return unsafeBitCast(RLMGetObject(rlmRealm, type.className(), key), Optional<T>.self)
// FIXME: use T.className()
return unsafeBitCast(RLMGetObject(rlmRealm, (T.self as Object.Type).className(), key), Optional<T>.self)
}


Expand Down

0 comments on commit d404ffd

Please sign in to comment.