Skip to content

Commit

Permalink
Make mogenerator:readonly work for Swift by rendering the attribute a…
Browse files Browse the repository at this point in the history
…s a read-only computed property.
  • Loading branch information
atomicbird committed Apr 29, 2015
1 parent 43f61d0 commit fc99ca4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions templates/machine.swift.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,26 @@ class _<$managedObjectClassName$>: <$customSuperentity$> {
<$if Attribute.hasDefinedAttributeType$>
<$if Attribute.hasScalarAttributeType$>
<$if Attribute.isReadonly$>
@NSManaged public
let <$Attribute.name$>: NSNumber?
public var <$Attribute.name$>: NSNumber?
{
self.willAccessValueForKey(<$managedObjectClassName$>Attributes.<$Attribute.name$>.rawValue)
let <$Attribute.name$> = self.primitiveValueForKey(<$managedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) as? NSNumber
self.didAccessValueForKey(<$managedObjectClassName$>Attributes.<$Attribute.name$>.rawValue)
return <$Attribute.name$>
}
<$else$>
@NSManaged public
var <$Attribute.name$>: NSNumber?
<$endif$>
<$else$>
<$if Attribute.isReadonly$>
@NSManaged public
let <$Attribute.name$>: <$Attribute.objectAttributeType$><$if Attribute.isOptional$>?<$endif$>
public var <$Attribute.name$>: <$Attribute.objectAttributeType$><$if Attribute.isOptional$>?<$endif$>
{
self.willAccessValueForKey(<$managedObjectClassName$>Attributes.<$Attribute.name$>.rawValue)
let <$Attribute.name$> = self.primitiveValueForKey(<$managedObjectClassName$>Attributes.<$Attribute.name$>.rawValue) as? <$Attribute.objectAttributeType$>
self.didAccessValueForKey(<$managedObjectClassName$>Attributes.<$Attribute.name$>.rawValue)
return <$Attribute.name$>
}
<$else$>
@NSManaged public
var <$Attribute.name$>: <$Attribute.objectAttributeType$><$if Attribute.isOptional$>?<$endif$>
Expand Down

0 comments on commit fc99ca4

Please sign in to comment.