Skip to content
This repository has been archived by the owner on Oct 31, 2018. It is now read-only.

Commit

Permalink
Remove the need to specify Spot.None
Browse files Browse the repository at this point in the history
For regular enums the default is no associated value
Specifying Spot.Type creates an associated type rather then forcing Spot.None for a basic case.
  • Loading branch information
amberstar committed Apr 25, 2015
1 parent c126815 commit 425f46a
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,46 @@
<relationship name="gender" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Gender" syncable="YES"/>
</entity>
<entity name="TestAssociatedEnum" representedClassName="TestAssociatedEnum" syncable="YES">
<attribute name="binaryType" attributeType="Binary" syncable="YES"/>
<attribute name="booleanType" attributeType="Boolean" syncable="YES"/>
<attribute name="dateType" attributeType="Date" syncable="YES"/>
<attribute name="decimalType" attributeType="Decimal" defaultValueString="0.0" syncable="YES"/>
<attribute name="doubleType" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
<attribute name="floatType" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
<attribute name="intType" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
<attribute name="stringType" attributeType="String" syncable="YES"/>
<attribute name="binaryType" attributeType="Binary" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="NSData"/>
</userInfo>
</attribute>
<attribute name="booleanType" attributeType="Boolean" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="Bool"/>
</userInfo>
</attribute>
<attribute name="dateType" attributeType="Date" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="NSDate"/>
</userInfo>
</attribute>
<attribute name="decimalType" attributeType="Decimal" defaultValueString="0.0" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="NSDecimalNumber"/>
</userInfo>
</attribute>
<attribute name="doubleType" attributeType="Double" defaultValueString="0.0" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="Double"/>
</userInfo>
</attribute>
<attribute name="floatType" attributeType="Float" defaultValueString="0.0" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="Float"/>
</userInfo>
</attribute>
<attribute name="intType" attributeType="Integer 32" defaultValueString="0" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="Int"/>
</userInfo>
</attribute>
<attribute name="stringType" attributeType="String" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="String"/>
</userInfo>
</attribute>
<attribute name="transformableColorType" attributeType="Transformable" valueTransformerName="UIColorTransform" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="UIColor"/>
Expand All @@ -52,21 +84,53 @@
</userInfo>
</entity>
<entity name="TestAssociatedOptionalEnum" representedClassName="TestAssociatedOptionalEnum" syncable="YES">
<attribute name="binaryType" optional="YES" attributeType="Binary" syncable="YES"/>
<attribute name="booleanType" optional="YES" attributeType="Boolean" syncable="YES"/>
<attribute name="dateType" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="decimalType" optional="YES" attributeType="Decimal" defaultValueString="0.0" syncable="YES"/>
<attribute name="doubleType" optional="YES" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
<attribute name="floatType" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
<attribute name="intType" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
<attribute name="stringType" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="binaryType" optional="YES" attributeType="Binary" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="NSData"/>
</userInfo>
</attribute>
<attribute name="booleanType" optional="YES" attributeType="Boolean" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="Bool"/>
</userInfo>
</attribute>
<attribute name="dateType" optional="YES" attributeType="Date" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="NSDate"/>
</userInfo>
</attribute>
<attribute name="decimalType" optional="YES" attributeType="Decimal" defaultValueString="0.0" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="NSDecimalNumber"/>
</userInfo>
</attribute>
<attribute name="doubleType" optional="YES" attributeType="Double" defaultValueString="0.0" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="Double"/>
</userInfo>
</attribute>
<attribute name="floatType" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="Float"/>
</userInfo>
</attribute>
<attribute name="intType" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="Int"/>
</userInfo>
</attribute>
<attribute name="stringType" optional="YES" attributeType="String" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="String"/>
</userInfo>
</attribute>
<attribute name="transformableColorType" optional="YES" attributeType="Transformable" valueTransformerName="UIColorTransform" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="UIColor"/>
</userInfo>
</attribute>
<relationship name="decodableToManyType" optional="YES" toMany="YES" deletionRule="No Action" destinationEntity="Employee" syncable="YES"/>
<relationship name="decodableToOneType" optional="YES" maxCount="1" deletionRule="No Action" destinationEntity="Employee" syncable="YES"/>
<relationship name="decodableToManyType" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Employee" syncable="YES"/>
<relationship name="decodableToOneType" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Employee" syncable="YES"/>
<userInfo>
<entry key="Spot.Enum" value="YES"/>
</userInfo>
Expand Down Expand Up @@ -261,16 +325,8 @@
</userInfo>
</entity>
<entity name="TestRegEnum" representedClassName="TestRegEnum" syncable="YES">
<attribute name="cold" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="Spot.None"/>
</userInfo>
</attribute>
<attribute name="hot" optional="YES" attributeType="Double" defaultValueString="0.0" syncable="YES">
<userInfo>
<entry key="Spot.Type" value="Spot.None"/>
</userInfo>
</attribute>
<attribute name="cold" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
<attribute name="hot" optional="YES" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
<userInfo>
<entry key="Spot.Enum" value="YES"/>
</userInfo>
Expand Down Expand Up @@ -319,20 +375,20 @@
<element name="Employee" positionX="-19874" positionY="-10837" width="128" height="73"/>
<element name="Gender" positionX="-20295" positionY="-11142" width="128" height="73"/>
<element name="Grandchild" positionX="-19838" positionY="-11110" width="128" height="88"/>
<element name="TestAssociatedEnum" positionX="-20034" positionY="-10755" width="128" height="208"/>
<element name="TestAssociatedOptionalEnum" positionX="-20124" positionY="-10476" width="128" height="208"/>
<element name="TestChild" positionX="-19910" positionY="-11385" width="128" height="103"/>
<element name="TestCollections" positionX="-20754" positionY="-10872" width="128" height="88"/>
<element name="TestDefaults" positionX="-20898" positionY="-11358" width="128" height="208"/>
<element name="TestDefaultsChild" positionX="-20601" positionY="-11340" width="128" height="58"/>
<element name="TestRawEnum" positionX="-20423" positionY="-10645" width="128" height="88"/>
<element name="TestImmutableOptionalTypes" positionX="-20592" positionY="-10639" width="128" height="163"/>
<element name="TestImmutableTypes" positionX="-20763" positionY="-10639" width="128" height="163"/>
<element name="TestOptionalTypes" positionX="-20925" positionY="-10881" width="128" height="163"/>
<element name="TestOverrideType" positionX="-20718" positionY="-11107" width="128" height="73"/>
<element name="TestRawEnum" positionX="-20423" positionY="-10645" width="128" height="88"/>
<element name="TestRegEnum" positionX="-20250" positionY="-10638" width="128" height="73"/>
<element name="TestRelationships" positionX="-20304" positionY="-11347" width="128" height="88"/>
<element name="TestTransformable" positionX="-20576" positionY="-10863" width="263" height="103"/>
<element name="TestTypes" positionX="-20927" positionY="-10684" width="128" height="163"/>
<element name="TestRegEnum" positionX="-20250" positionY="-10636" width="128" height="73"/>
<element name="TestAssociatedEnum" positionX="-20034" positionY="-10755" width="128" height="208"/>
<element name="TestAssociatedOptionalEnum" positionX="-20124" positionY="-10476" width="128" height="208"/>
</elements>
</model>
8 changes: 4 additions & 4 deletions Templates/machine.swift.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ extension <$managedObjectClassName$> : Encodable {

<$procedure writeRawValueCaseForAttribute Attribute$><$if Attribute.userInfo.Spot.Value$> = <$if userInfo.Spot.Type == String$>"<$endif$><$ Attribute.userInfo.Spot.Value$><$if userInfo.Spot.Type == String$>"<$endif$><$endif$><$endprocedure$>

<$procedure writeAssociatedValueCaseForAttribute Attribute$><$if Attribute.userInfo.Spot.Type != Spot.None$>(<$call getTypeForAttribute Attribute$>)<$endif$><$endprocedure$>
<$procedure writeAssociatedValueCaseForAttribute Attribute$><$if Attribute.userInfo.Spot.Type$>(<$Attribute.userInfo.Spot.Type$><$if Attribute.isOptional$>?<$endif$>)<$endif$><$endprocedure$>

<$procedure writeEnumCaseForAttribute Attribute$>case <$Attribute.name.initialCapitalString$> <$if userInfo.Spot.Type$><$call writeRawValueCaseForAttribute Attribute$><$else$><$call writeAssociatedValueCaseForAttribute Attribute$><$endif$><$endprocedure$>

Expand All @@ -117,7 +117,7 @@ extension <$managedObjectClassName$> : Encodable {
<$procedure writeEnumCaseForRelationship Relationship$>case <$Relationship.name.initialCapitalString$> <$if userInfo.Spot.Type$><$call writeRawValueCaseForRelationship Relationship$><$else$><$call writeAssociatedValueCaseForRelationship Relationship$><$endif$><$endprocedure$>


<$procedure writeAttributeDecodeAssociatedSwitchCaseForEnum Attribute$>if let value: <$call getTypeForAttribute Attribute$> = decoder.decode("value")<$if Attribute.attributeType == 1800$> >>> <$Attribute.valueTransformerName$>.reverseTransform<$endif$><$if Attribute.isOptional$> >>> asOptional<$endif$> {
<$procedure writeAttributeDecodeAssociatedSwitchCaseForEnum Attribute$>if let value: <$Attribute.userInfo.Spot.Type$><$if Attribute.isOptional$>?<$endif$> = decoder.decode("value")<$if Attribute.attributeType == 1800$> >>> <$Attribute.valueTransformerName$>.reverseTransform<$endif$><$if Attribute.isOptional$> >>> asOptional<$endif$> {
self = <$managedObjectClassName$>.<$Attribute.name.initialCapitalString$>(value)
} else { return nil }<$endprocedure$>

Expand All @@ -130,7 +130,7 @@ extension <$managedObjectClassName$> : Encodable {
} else { return nil }<$endprocedure$>

<$procedure writeAttributeDecodeSwitchCaseForEnumCase Attribute$>case "<$Attribute.name$>":
<$if userInfo.Spot.Type$><$call writeAttributeDecodeRawSwitchCaseForEnum Attribute$><$elseif Attribute.userInfo.Spot.Type != Spot.None$><$call writeAttributeDecodeAssociatedSwitchCaseForEnum Attribute$><$else$><$call writeAttributeDecodeBasicSwitchCaseForEnum Attribute$><$endif$><$endprocedure$>
<$if userInfo.Spot.Type$><$call writeAttributeDecodeRawSwitchCaseForEnum Attribute$><$elseif Attribute.userInfo.Spot.Type$><$call writeAttributeDecodeAssociatedSwitchCaseForEnum Attribute$><$else$><$call writeAttributeDecodeBasicSwitchCaseForEnum Attribute$><$endif$><$endprocedure$>

<$procedure writeRelationshipDecodeAssociatedSwitchCaseForEnum Relationship$>if let value: <$if Relationship.isToMany$>[<$endif$><$Relationship.destinationEntity.managedObjectClassName$><$if Relationship.isToMany$>]<$endif$><$if Relationship.isOptional$>?<$endif$> = decoder.decodeModel<$if Relationship.isToMany$>Array<$endif$>("value") <$if Relationship.isOptional$>>>> asOptional<$endif$>{
self = <$managedObjectClassName$>.<$Relationship.name.initialCapitalString$>(value)
Expand Down Expand Up @@ -158,7 +158,7 @@ extension <$managedObjectClassName$> : Encodable {
encoder.encode("<$Attribute.name$>", forKey: "type")
encoder.encode(value<$if Attribute.attributeType == 1800$> >>> <$Attribute.valueTransformerName$>.transform<$endif$>, forKey: "value")<$endprocedure$>

<$procedure writeAttributeEncodeSwitchCaseForEnumCase Attribute$><$if userInfo.Spot.Type$><$call writeAttributeEncodeRawSwitchCaseForEnum Attribute$><$elseif Attribute.userInfo.Spot.Type != Spot.None$><$call writeAttributeEncodeAssociatedSwitchCaseForEnum Attribute$><$else$><$call writeAttributeEncodeBasicSwitchCaseForEnum Attribute$><$endif$><$endprocedure$>
<$procedure writeAttributeEncodeSwitchCaseForEnumCase Attribute$><$if userInfo.Spot.Type$><$call writeAttributeEncodeRawSwitchCaseForEnum Attribute$><$elseif Attribute.userInfo.Spot.Type$><$call writeAttributeEncodeAssociatedSwitchCaseForEnum Attribute$><$else$><$call writeAttributeEncodeBasicSwitchCaseForEnum Attribute$><$endif$><$endprocedure$>

<$procedure writeRelationshipEncodeBasicSwitchCaseForEnum Relationship$>case let .<$Relationship.name.initialCapitalString$>:
encoder.encode("<$Relationship.name$>", forKey: "type")<$endprocedure$>
Expand Down

0 comments on commit 425f46a

Please sign in to comment.