Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-ios
Commits
635f2b3c
Commit
635f2b3c
authored
Oct 06, 2017
by
Eyad Hasan
Browse files
Mapping objects
Mapping the JSON keys to our objects, eventually we will have it displaying. Soon^TM
parent
0d633222
Changes
2
Hide whitespace changes
Inline
Side-by-side
WhatsOpen/WhatsOpen/Object Model/examplejson.swift
View file @
635f2b3c
...
...
@@ -2,6 +2,7 @@
import
Foundation
import
RealmSwift
import
ObjectMapper
//
// MARK: - Data Model
//
...
...
@@ -21,13 +22,25 @@ enum Day: Int {
class
Facility
:
Object
{
dynamic
var
slug
=
""
dynamic
var
facilityName
=
""
let
facilityLocation
=
Locations
()
let
category
=
Categories
()
let
facilityTags
=
List
<
FacilityTags
>
()
let
mainSchedule
=
MainSchedule
()
let
specialSchedule
=
SpecialSchedule
()
var
facilityLocation
=
Locations
()
var
category
=
Categories
()
var
facilityTags
=
List
<
FacilityTags
>
()
var
mainSchedule
=
MainSchedule
()
var
specialSchedule
=
SpecialSchedule
()
required
convenience
init
?(
map
:
Map
)
{
self
.
init
()
}
func
mapping
(
map
:
Map
){
slug
<-
map
[
"slug"
]
facilityName
<-
map
[
"facility_name"
]
facilityLocation
<-
map
[
"facility_location"
]
category
<-
map
[
"facility_category"
]
facilityTags
<-
map
[
"facility_product_tags"
]
mainSchedule
<-
map
[
"main_schedule"
]
specialSchedule
<-
map
[
"special_schedules"
]
}
}
...
...
@@ -40,6 +53,19 @@ class Locations: Object {
dynamic
var
campus
=
""
dynamic
var
onCampus
=
false
required
convenience
init
?(
map
:
Map
){
self
.
init
()
}
func
mapping
(
map
:
Map
){
id
<-
map
[
"id"
]
created
<-
map
[
"created"
]
lastmodified
<-
map
[
"modified"
]
building
<-
map
[
"building"
]
address
<-
map
[
"address"
]
campus
<-
map
[
"campus_region"
]
onCampus
<-
map
[
"on_campus"
]
}
}
class
Categories
:
Object
{
...
...
@@ -48,6 +74,16 @@ class Categories: Object {
dynamic
var
modified
=
""
dynamic
var
categoryName
=
""
required
convenience
init
?(
map
:
Map
){
self
.
init
()
}
func
mapping
(
map
:
Map
){
id
<-
map
[
"id"
]
created
<-
map
[
"created"
]
modified
<-
map
[
"modified"
]
categoryName
<-
map
[
"name"
]
}
}
class
FacilityTags
:
Object
{
...
...
@@ -57,7 +93,7 @@ class FacilityTags: Object {
class
MainSchedule
:
Object
{
dynamic
var
id
=
0
let
openTimes
=
List
<
OpenTimes
>
()
var
openTimes
=
List
<
OpenTimes
>
()
dynamic
var
lastModified
=
""
dynamic
var
name
=
""
dynamic
var
validStart
=
""
...
...
@@ -65,6 +101,19 @@ class MainSchedule: Object {
dynamic
var
twentyFourHours
=
false
required
convenience
init
?(
map
:
Map
){
self
.
init
()
}
func
mapping
(
map
:
Map
){
id
<-
map
[
"id"
]
openTimes
<-
map
[
"open_times"
]
lastModified
<-
map
[
"modified"
]
name
<-
map
[
"name"
]
validStart
<-
map
[
"valid_start"
]
validEnd
<-
map
[
"valid_end"
]
twentyFourHours
<-
map
[
"twenty_four_hours"
]
}
}
class
SpecialSchedule
:
Object
{
...
...
WhatsOpen/WhatsOpen/SRCTNetworkController.swift
View file @
635f2b3c
...
...
@@ -15,7 +15,7 @@ class SRCTNetworkController: NSObject {
//https://api.srct.gmu.edu/whatsopen/v2/facilities/?format=json
public
static
func
performDownload
(
completion
:
@escaping
(
_
result
:
Array
<
Facility
>
)
->
Void
)
{
let
facility
=
Facility
()
let
requestURL
:
NSURL
=
NSURL
(
string
:
"https://api.srct.gmu.edu/whatsopen/v2/facilities/?format=json"
)
!
let
urlRequest
:
NSMutableURLRequest
=
NSMutableURLRequest
(
url
:
requestURL
as
URL
)
let
session
=
URLSession
.
shared
...
...
@@ -31,8 +31,9 @@ class SRCTNetworkController: NSObject {
do
{
let
realm
=
try!
Realm
()
let
json
=
try
?
JSONSerialization
.
jsonObject
(
with
:
dataN
,
options
:
[])
Object
.
init
(
value
:
"slug"
)
try!
realm
.
write
{
realm
.
add
(
facility
,
update
:
true
)
}
}
...
...
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