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
eb8df7a1
Unverified
Commit
eb8df7a1
authored
Jan 04, 2018
by
Zach Knox
Browse files
download and update VC and Realm
No UI showing this yet
parent
7cf799fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
WhatsOpen/WhatsOpen/Object Model/examplejson.swift
View file @
eb8df7a1
...
...
@@ -210,7 +210,7 @@ class OpenTimes: Object, Mappable {
}
class
Alert
:
Object
,
Mappable
{
class
Alert
:
Object
,
MapContext
,
Mappable
{
@objc
dynamic
var
id
=
0
@objc
dynamic
var
created
=
""
@objc
dynamic
var
lastModified
=
""
...
...
WhatsOpen/WhatsOpen/Views/FacilitiesListViewController.swift
View file @
eb8df7a1
...
...
@@ -13,6 +13,7 @@ import RealmSwift
//Realm Model
class
FacilitiesModel
:
Object
{
var
facilities
=
List
<
Facility
>
()
var
alerts
=
List
<
Alert
>
()
@objc
dynamic
var
lastUpdated
=
Date
()
@objc
dynamic
let
id
=
0
}
...
...
@@ -23,6 +24,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
let
realm
=
try!
Realm
()
var
facilitiesArray
=
List
<
Facility
>
()
var
alertsList
=
List
<
Alert
>
()
// array of facilities that pass the current filters
var
filteredFacilities
=
List
<
Facility
>
()
...
...
@@ -404,9 +406,43 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
}
}
}
SRCTNetworkController
.
performAlertsDownload
{
(
alerts
)
in
if
(
alerts
==
nil
)
{
DispatchQueue
.
main
.
async
{
let
results
=
self
.
realm
.
objects
(
FacilitiesModel
.
self
)
if
results
.
count
>
0
{
let
model
=
results
[
0
]
let
alertsFromDB
=
model
.
alerts
let
lastUpdated
=
model
.
lastUpdated
self
.
alertsList
=
alertsFromDB
}
else
{
self
.
alertsList
=
List
<
Alert
>
()
}
}
}
else
{
self
.
alertsList
=
alerts
!
DispatchQueue
.
main
.
async
{
let
model
=
FacilitiesModel
()
model
.
alerts
=
alerts
!
let
results
=
self
.
realm
.
objects
(
FacilitiesModel
.
self
)
if
results
.
count
==
0
{
try!
self
.
realm
.
write
{
self
.
realm
.
add
(
model
)
}
}
else
{
let
fromRealm
=
results
[
0
]
try!
self
.
realm
.
write
{
fromRealm
.
alerts
=
model
.
alerts
}
}
}
}
}
}
...
...
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