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
fe5010e8
Commit
fe5010e8
authored
Jun 03, 2022
by
xlu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added feature fetching from url
parent
e6b4df42
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
15 deletions
+66
-15
.DS_Store
.DS_Store
+0
-0
.DS_Store
iOSNetworkJSON/.DS_Store
+0
-0
project.pbxproj
iOSNetworkJSON/iOSNetworkJSON.xcodeproj/project.pbxproj
+4
-0
UserInterfaceState.xcuserstate
...xcuserdata/xlu.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
Main.storyboard
iOSNetworkJSON/iOSNetworkJSON/Base.lproj/Main.storyboard
+13
-4
CDHandler.swift
iOSNetworkJSON/iOSNetworkJSON/CDHandler.swift
+28
-0
ViewController.swift
iOSNetworkJSON/iOSNetworkJSON/ViewController.swift
+14
-9
contents
...workJSON.xcdatamodeld/iOSNetworkJSON.xcdatamodel/contents
+7
-2
No files found.
.DS_Store
0 → 100644
View file @
fe5010e8
File added
iOSNetworkJSON/.DS_Store
0 → 100644
View file @
fe5010e8
File added
iOSNetworkJSON/iOSNetworkJSON.xcodeproj/project.pbxproj
View file @
fe5010e8
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
objects
=
{
objects
=
{
/* Begin PBXBuildFile section */
/* Begin PBXBuildFile section */
262804D128498A5A000E1A24
/* CDHandler.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
262804D028498A5A000E1A24
/* CDHandler.swift */
;
};
2672E4CD2841747500D1D02C
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
2672E4CC2841747500D1D02C
/* AppDelegate.swift */
;
};
2672E4CD2841747500D1D02C
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
2672E4CC2841747500D1D02C
/* AppDelegate.swift */
;
};
2672E4CF2841747500D1D02C
/* SceneDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
2672E4CE2841747500D1D02C
/* SceneDelegate.swift */
;
};
2672E4CF2841747500D1D02C
/* SceneDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
2672E4CE2841747500D1D02C
/* SceneDelegate.swift */
;
};
2672E4D12841747500D1D02C
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
2672E4D02841747500D1D02C
/* ViewController.swift */
;
};
2672E4D12841747500D1D02C
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
2672E4D02841747500D1D02C
/* ViewController.swift */
;
};
...
@@ -18,6 +19,7 @@
...
@@ -18,6 +19,7 @@
/* End PBXBuildFile section */
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
/* Begin PBXFileReference section */
262804D028498A5A000E1A24
/* CDHandler.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CDHandler.swift
;
sourceTree
=
"<group>"
;
};
2672E4C92841747500D1D02C
/* iOSNetworkJSON.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
iOSNetworkJSON.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
2672E4C92841747500D1D02C
/* iOSNetworkJSON.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
iOSNetworkJSON.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
2672E4CC2841747500D1D02C
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
2672E4CC2841747500D1D02C
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
2672E4CE2841747500D1D02C
/* SceneDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
SceneDelegate.swift
;
sourceTree
=
"<group>"
;
};
2672E4CE2841747500D1D02C
/* SceneDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
SceneDelegate.swift
;
sourceTree
=
"<group>"
;
};
...
@@ -69,6 +71,7 @@
...
@@ -69,6 +71,7 @@
2672E4DA2841747600D1D02C
/* LaunchScreen.storyboard */
,
2672E4DA2841747600D1D02C
/* LaunchScreen.storyboard */
,
2672E4DD2841747600D1D02C
/* Info.plist */
,
2672E4DD2841747600D1D02C
/* Info.plist */
,
2672E4D52841747500D1D02C
/* iOSNetworkJSON.xcdatamodeld */
,
2672E4D52841747500D1D02C
/* iOSNetworkJSON.xcdatamodeld */
,
262804D028498A5A000E1A24
/* CDHandler.swift */
,
);
);
path
=
iOSNetworkJSON
;
path
=
iOSNetworkJSON
;
sourceTree
=
"<group>"
;
sourceTree
=
"<group>"
;
...
@@ -143,6 +146,7 @@
...
@@ -143,6 +146,7 @@
isa
=
PBXSourcesBuildPhase
;
isa
=
PBXSourcesBuildPhase
;
buildActionMask
=
2147483647
;
buildActionMask
=
2147483647
;
files
=
(
files
=
(
262804D128498A5A000E1A24
/* CDHandler.swift in Sources */
,
2672E4D12841747500D1D02C
/* ViewController.swift in Sources */
,
2672E4D12841747500D1D02C
/* ViewController.swift in Sources */
,
2672E4CD2841747500D1D02C
/* AppDelegate.swift in Sources */
,
2672E4CD2841747500D1D02C
/* AppDelegate.swift in Sources */
,
26EE2CCF28419B02004C74AF
/* ProductTableViewCell.swift in Sources */
,
26EE2CCF28419B02004C74AF
/* ProductTableViewCell.swift in Sources */
,
...
...
iOSNetworkJSON/iOSNetworkJSON.xcodeproj/project.xcworkspace/xcuserdata/xlu.xcuserdatad/UserInterfaceState.xcuserstate
View file @
fe5010e8
No preview for this file type
iOSNetworkJSON/iOSNetworkJSON/Base.lproj/Main.storyboard
View file @
fe5010e8
...
@@ -27,16 +27,25 @@
...
@@ -27,16 +27,25 @@
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"414"
height=
"120"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"414"
height=
"120"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
<subviews>
<subviews>
<textField
opaque=
"NO"
contentMode=
"scaleToFill"
fixedFrame=
"YES"
contentHorizontalAlignment=
"left"
contentVerticalAlignment=
"center"
borderStyle=
"roundedRect"
textAlignment=
"natural"
minimumFontSize=
"17"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"F0x-Vp-2XT"
>
<textField
opaque=
"NO"
contentMode=
"scaleToFill"
contentHorizontalAlignment=
"left"
contentVerticalAlignment=
"center"
borderStyle=
"roundedRect"
textAlignment=
"natural"
minimumFontSize=
"17"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"F0x-Vp-2XT"
>
<rect
key=
"frame"
x=
"53"
y=
"43"
width=
"97"
height=
"34"
/>
<rect
key=
"frame"
x=
"53"
y=
"21"
width=
"308"
height=
"56"
/>
<autoresizingMask
key=
"autoresizingMask"
flexibleMaxX=
"YES"
flexibleMaxY=
"YES"
/>
<constraints>
<constraint
firstAttribute=
"height"
constant=
"34"
id=
"2mV-m0-yp4"
/>
<constraint
firstAttribute=
"width"
constant=
"200"
id=
"tBl-ow-DqZ"
/>
</constraints>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"14"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"14"
/>
<textInputTraits
key=
"textInputTraits"
/>
<textInputTraits
key=
"textInputTraits"
/>
</textField>
</textField>
</subviews>
</subviews>
<constraints>
<constraint
firstAttribute=
"trailingMargin"
secondItem=
"F0x-Vp-2XT"
secondAttribute=
"trailing"
constant=
"33"
id=
"537-Qt-N2b"
/>
<constraint
firstAttribute=
"bottomMargin"
secondItem=
"F0x-Vp-2XT"
secondAttribute=
"bottom"
constant=
"32"
id=
"EEb-so-rrb"
/>
<constraint
firstItem=
"F0x-Vp-2XT"
firstAttribute=
"top"
secondItem=
"ed9-dy-DXb"
secondAttribute=
"topMargin"
constant=
"10"
id=
"WLa-XA-XUs"
/>
<constraint
firstItem=
"F0x-Vp-2XT"
firstAttribute=
"leading"
secondItem=
"ed9-dy-DXb"
secondAttribute=
"leadingMargin"
constant=
"33"
id=
"cH9-lt-Egl"
/>
</constraints>
</tableViewCellContentView>
</tableViewCellContentView>
<connections>
<connections>
<outlet
property=
"ProductDescription"
destination=
"F0x-Vp-2XT"
id=
"
lo4-Q5-Rwu
"
/>
<outlet
property=
"ProductDescription"
destination=
"F0x-Vp-2XT"
id=
"
KTu-S0-rEO
"
/>
</connections>
</connections>
</tableViewCell>
</tableViewCell>
</prototypes>
</prototypes>
...
...
iOSNetworkJSON/iOSNetworkJSON/CDHandler.swift
0 → 100644
View file @
fe5010e8
//
// CDHandler.swift
// iOSNetworkJSON
//
// Created by xlu on 6/2/22.
//
import
UIKit
import
CoreData
class
CDHandler
{
private
let
viewContext
:
NSManagedObjectContext
=
(
UIApplication
.
shared
.
delegate
as!
AppDelegate
)
.
persistentContainer
.
viewContext
func
add
<
T
:
NSManagedObject
>
(
_
type
:
T
.
Type
)
->
T
?
{
guard
let
entityName
=
T
.
entity
()
.
name
else
{
return
nil
}
guard
let
entity
=
NSEntityDescription
.
entity
(
forEntityName
:
entityName
,
in
:
viewContext
)
else
{
return
nil
}
let
object
=
T
(
entity
:
entity
,
insertInto
:
viewContext
)
return
object
}
func
save
(){
do
{
try
viewContext
.
save
()
}
catch
{
print
(
error
.
localizedDescription
)
}
}
}
iOSNetworkJSON/iOSNetworkJSON/ViewController.swift
View file @
fe5010e8
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
//
//
import
UIKit
import
UIKit
import
CoreData
struct
ProductStore
:
Codable
{
struct
ProductStore
:
Codable
{
...
@@ -31,17 +32,26 @@ struct Product: Codable {
...
@@ -31,17 +32,26 @@ struct Product: Codable {
class
ViewController
:
UIViewController
{
class
ViewController
:
UIViewController
{
let
coreDataHandler
=
CDHandler
()
@IBOutlet
weak
var
tableView
:
UITableView
!
@IBOutlet
weak
var
tableView
:
UITableView
!
var
allProducts
=
[
Product
]()
var
allProducts
=
[
Product
]()
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
getAllProducts
()
getAllProducts
(
productCompletionHandler
:
{
productall
,
error
in
if
let
products
=
productall
?
.
products
{
self
.
allProducts
=
products
DispatchQueue
.
main
.
async
{
self
.
tableView
.
reloadData
()
}
}
})
}
}
private
func
getAllProducts
(){
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"
)
}
}
...
@@ -51,13 +61,8 @@ class ViewController: UIViewController{
...
@@ -51,13 +61,8 @@ class ViewController: UIViewController{
guard
let
productall
=
try
?
JSONDecoder
()
.
decode
(
ProductStore
.
self
,
from
:
data
)
else
{
guard
let
productall
=
try
?
JSONDecoder
()
.
decode
(
ProductStore
.
self
,
from
:
data
)
else
{
fatalError
(
"decode error"
)
fatalError
(
"decode error"
)
}
}
for
element
in
productall
.
products
{
productCompletionHandler
(
productall
,
nil
)
self
.
allProducts
.
append
(
element
)
}
}
DispatchQueue
.
main
.
async
{
[
self
]
in
tableView
.
reloadData
()
}
}
}
.
resume
()
}
.
resume
()
}
}
...
...
iOSNetworkJSON/iOSNetworkJSON/iOSNetworkJSON.xcdatamodeld/iOSNetworkJSON.xcdatamodel/contents
View file @
fe5010e8
<?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=
"Entity"
representedClassName=
"Entity"
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"
/>
<attribute
name=
"id"
optional=
"YES"
attributeType=
"Integer 32"
defaultValueString=
"0"
usesScalarValueType=
"YES"
/>
<attribute
name=
"title"
optional=
"YES"
attributeType=
"String"
/>
</entity>
<elements>
<elements>
<element
name=
"
Entity"
positionX=
"-63"
positionY=
"-18"
width=
"128"
height=
"4
3"
/>
<element
name=
"
SavedProduct"
positionX=
"-63"
positionY=
"-18"
width=
"128"
height=
"10
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