Changes Cheat.name to non-optional

This commit is contained in:
Riley Testut 2018-12-04 17:05:14 -08:00
parent 007092f875
commit 9a186ffea9
4 changed files with 10 additions and 6 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14460.32" systemVersion="18A391" minimumToolsVersion="Xcode 7.0" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="1.0"> <model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14460.32" systemVersion="18B75" minimumToolsVersion="Xcode 7.0" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="1.0">
<entity name="Cheat" representedClassName="Cheat" syncable="YES"> <entity name="Cheat" representedClassName="Cheat" syncable="YES">
<attribute name="code" attributeType="String" syncable="YES"/> <attribute name="code" attributeType="String" syncable="YES"/>
<attribute name="creationDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/> <attribute name="creationDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="identifier" attributeType="String" syncable="YES"/> <attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="isEnabled" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="NO" syncable="YES"/> <attribute name="isEnabled" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="NO" syncable="YES"/>
<attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/> <attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/> <attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="type" attributeType="Transformable" syncable="YES"> <attribute name="type" attributeType="Transformable" syncable="YES">
<userInfo> <userInfo>
<entry key="attributeValueClassName" value="CheatType"/> <entry key="attributeValueClassName" value="CheatType"/>

View File

@ -24,7 +24,7 @@ public class _Cheat: NSManagedObject
@NSManaged public var modifiedDate: Date @NSManaged public var modifiedDate: Date
@NSManaged public var name: String? @NSManaged public var name: String
@NSManaged public var type: CheatType @NSManaged public var type: CheatType

View File

@ -18,11 +18,11 @@ extension EmulatorCore
} }
catch EmulatorCore.CheatError.invalid catch EmulatorCore.CheatError.invalid
{ {
print("Invalid cheat:", cheat.name ?? "Unnamed Cheat", cheat.code) print("Invalid cheat:", cheat.name, cheat.code)
} }
catch catch
{ {
print("Unknown Cheat Error:", error, cheat.name ?? "Unnamed Cheat", cheat.code) print("Unknown Cheat Error:", error, cheat.name, cheat.code)
} }
} }

View File

@ -16,6 +16,7 @@ extension CheatValidator
{ {
case invalidCode case invalidCode
case invalidName case invalidName
case invalidGame
case duplicateName case duplicateName
case duplicateCode case duplicateCode
} }
@ -28,7 +29,10 @@ struct CheatValidator
func validate(_ cheat: Cheat) throws func validate(_ cheat: Cheat) throws
{ {
guard let name = cheat.name, let game = cheat.game else { throw Error.invalidName } let name = cheat.name
guard !name.isEmpty else { throw Error.invalidName }
guard let game = cheat.game else { throw Error.invalidGame }
let code = cheat.code let code = cheat.code