Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实际开发中有可能后台返回的json数据字段对应的值是<null>,对应到ios的字典里面就是一个NSNull的实例,这里做了一个判断,如果… #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "89B833691B842549002C60EB"
BuildableName = "Reflect.app"
BlueprintName = "Reflect"
ReferencedContainer = "container:Reflect.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "89B8337E1B84254A002C60EB"
BuildableName = "ReflectTests.xctest"
BlueprintName = "ReflectTests"
ReferencedContainer = "container:Reflect.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "89B833691B842549002C60EB"
BuildableName = "Reflect.app"
BlueprintName = "Reflect"
ReferencedContainer = "container:Reflect.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "89B833691B842549002C60EB"
BuildableName = "Reflect.app"
BlueprintName = "Reflect"
ReferencedContainer = "container:Reflect.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "89B833691B842549002C60EB"
BuildableName = "Reflect.app"
BlueprintName = "Reflect"
ReferencedContainer = "container:Reflect.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Reflect.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>89B833691B842549002C60EB</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>89B8337E1B84254A002C60EB</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
24 changes: 22 additions & 2 deletions Reflect/Reflect/Dict2Model/Reflect+Parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ extension Reflect{
model.setValue(dict[key]?.boolValue, forKeyPath: name)

}else{
model.setValue(dict[key], forKeyPath: name)

var dictValue = dict[key]

if let tmp = dictValue {

if tmp.isEqual(NSNull.init()) {

dictValue = nil
}
}

model.setValue(dictValue, forKeyPath: name)
}


Expand All @@ -75,7 +86,16 @@ extension Reflect{

//这里是模型
//首选判断字典中是否有值
let dictValue = dict[key]

var dictValue = dict[key]

if let tmp = dictValue {

if tmp.isEqual(NSNull.init()) {

dictValue = nil
}
}

if dictValue != nil { //字典中有模型

Expand Down