Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
iOSNetworkAssignment
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xiyang Lu
iOSNetworkAssignment
Commits
30dded6d
Commit
30dded6d
authored
Jun 03, 2022
by
xlu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added core data save
parent
fe5010e8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
4 deletions
+27
-4
UserInterfaceState.xcuserstate
...xcuserdata/xlu.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
CDHandler.swift
iOSNetworkJSON/iOSNetworkJSON/CDHandler.swift
+1
-0
ViewController.swift
iOSNetworkJSON/iOSNetworkJSON/ViewController.swift
+16
-0
contents
...workJSON.xcdatamodeld/iOSNetworkJSON.xcdatamodel/contents
+10
-4
No files found.
iOSNetworkJSON/iOSNetworkJSON.xcodeproj/project.xcworkspace/xcuserdata/xlu.xcuserdatad/UserInterfaceState.xcuserstate
View file @
30dded6d
No preview for this file type
iOSNetworkJSON/iOSNetworkJSON/CDHandler.swift
View file @
30dded6d
...
@@ -21,6 +21,7 @@ class CDHandler {
...
@@ -21,6 +21,7 @@ class CDHandler {
func
save
(){
func
save
(){
do
{
do
{
try
viewContext
.
save
()
try
viewContext
.
save
()
print
(
"Save Good"
)
}
catch
{
}
catch
{
print
(
error
.
localizedDescription
)
print
(
error
.
localizedDescription
)
}
}
...
...
iOSNetworkJSON/iOSNetworkJSON/ViewController.swift
View file @
30dded6d
...
@@ -51,6 +51,22 @@ class ViewController: UIViewController{
...
@@ -51,6 +51,22 @@ class ViewController: UIViewController{
}
}
private
func
saveToCore
(
productsArray
:
Array
<
Product
>
){
for
ele
in
productsArray
{
guard
let
product
=
coreDataHandler
.
add
(
SavedProduct
.
self
)
else
{
print
(
"failed"
);
return
}
let
id
=
Int32
(
ele
.
id
)
let
brand
=
ele
.
brand
let
title
=
ele
.
title
product
.
id
=
id
product
.
title
=
title
product
.
brand
=
brand
coreDataHandler
.
save
()
}
}
private
func
getAllProducts
(
productCompletionHandler
:
@escaping
(
ProductStore
?,
Error
?)
->
Void
){
private
func
getAllProducts
(
productCompletionHandler
:
@escaping
(
ProductStore
?,
Error
?)
->
Void
){
guard
let
url
=
URL
(
string
:
"https://dummyjson.com/products"
)
else
{
guard
let
url
=
URL
(
string
:
"https://dummyjson.com/products"
)
else
{
fatalError
(
"URL Failed"
)
fatalError
(
"URL Failed"
)
...
...
iOSNetworkJSON/iOSNetworkJSON/iOSNetworkJSON.xcdatamodeld/iOSNetworkJSON.xcdatamodel/contents
View file @
30dded6d
<?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=
"17709"
systemVersion=
"19H1715"
minimumToolsVersion=
"Automatic"
sourceLanguage=
"Swift"
userDefinedModelVersionIdentifier=
""
>
<model
type=
"com.apple.IDECoreDataModeler.DataModel"
documentVersion=
"1.0"
lastSavedToolsVersion=
"17709"
systemVersion=
"19H1715"
minimumToolsVersion=
"Automatic"
sourceLanguage=
"Swift"
userDefinedModelVersionIdentifier=
""
>
<entity
name=
"SavedProduct"
representedClassName=
".SavedProduct"
syncable=
"YES"
codeGenerationType=
"class"
>
<entity
name=
"SavedProduct"
representedClassName=
".SavedProduct"
syncable=
"YES"
codeGenerationType=
"class"
>
<attribute
name=
"attribute"
optional=
"YES"
/>
<attribute
name=
"brand"
optional=
"YES"
attributeType=
"String"
defaultValueString=
""
/>
<attribute
name=
"brand"
optional=
"YES"
attributeType=
"String"
/>
<attribute
name=
"category"
optional=
"YES"
attributeType=
"String"
/>
<attribute
name=
"descriptionProduct"
optional=
"YES"
attributeType=
"String"
/>
<attribute
name=
"discountPercentage"
optional=
"YES"
attributeType=
"Double"
usesScalarValueType=
"NO"
/>
<attribute
name=
"id"
optional=
"YES"
attributeType=
"Integer 32"
defaultValueString=
"0"
usesScalarValueType=
"YES"
/>
<attribute
name=
"id"
optional=
"YES"
attributeType=
"Integer 32"
defaultValueString=
"0"
usesScalarValueType=
"YES"
/>
<attribute
name=
"title"
optional=
"YES"
attributeType=
"String"
/>
<attribute
name=
"price"
optional=
"YES"
attributeType=
"Integer 32"
usesScalarValueType=
"YES"
/>
<attribute
name=
"rating"
optional=
"YES"
attributeType=
"Double"
usesScalarValueType=
"NO"
/>
<attribute
name=
"stock"
optional=
"YES"
attributeType=
"Integer 32"
usesScalarValueType=
"YES"
/>
<attribute
name=
"thumbnail"
optional=
"YES"
attributeType=
"String"
/>
<attribute
name=
"title"
optional=
"YES"
attributeType=
"String"
defaultValueString=
""
/>
</entity>
</entity>
<elements>
<elements>
<element
name=
"SavedProduct"
positionX=
"-63"
positionY=
"-18"
width=
"128"
height=
"1
0
3"
/>
<element
name=
"SavedProduct"
positionX=
"-63"
positionY=
"-18"
width=
"128"
height=
"1
9
3"
/>
</elements>
</elements>
</model>
</model>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment