Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Swift
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
Elixxir dApps SDK Swift
Commits
0b254c44
Commit
0b254c44
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Add Stored utility
parent
edf8b68a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!102
Release 1.0.0
,
!33
XXMessengerClient
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/XXMessengerClient/Utils/Stored.swift
+41
-0
41 additions, 0 deletions
Sources/XXMessengerClient/Utils/Stored.swift
Tests/XXMessengerClientTests/Messenger/Utils/StoredTests.swift
+18
-0
18 additions, 0 deletions
.../XXMessengerClientTests/Messenger/Utils/StoredTests.swift
with
59 additions
and
0 deletions
Sources/XXMessengerClient/Utils/Stored.swift
0 → 100644
+
41
−
0
View file @
0b254c44
import
XCTestDynamicOverlay
public
struct
Stored
<
Value
>
{
public
var
get
:
()
->
Value
public
var
set
:
(
Value
)
->
Void
public
func
callAsFunction
()
->
Value
{
get
()
}
}
extension
Stored
{
public
static
func
inMemory
(
_
value
:
Value
)
->
Stored
<
Value
>
{
let
memory
=
Memory
(
value
)
return
Stored
(
get
:
{
memory
.
value
},
set
:
{
memory
.
value
=
$0
}
)
}
public
static
func
inMemory
<
V
>
()
->
Stored
<
Optional
<
V
>>
where
Value
==
Optional
<
V
>
{
inMemory
(
nil
)
}
}
private
final
class
Memory
<
Value
>
{
init
(
_
value
:
Value
)
{
self
.
value
=
value
}
var
value
:
Value
}
extension
Stored
{
public
static
func
unimplemented
()
->
Stored
<
Value
>
{
Stored
<
Value
>
(
get
:
XCTUnimplemented
(
"
\(
Self
.
self
)
.get"
),
set
:
XCTUnimplemented
(
"
\(
Self
.
self
)
.set"
)
)
}
}
This diff is collapsed.
Click to expand it.
Tests/XXMessengerClientTests/Messenger/Utils/StoredTests.swift
0 → 100644
+
18
−
0
View file @
0b254c44
import
XCTest
@testable
import
XXMessengerClient
final
class
StoredTests
:
XCTestCase
{
func
testInMemory
()
throws
{
let
stored
:
Stored
<
String
?
>
=
.
inMemory
()
XCTAssertNil
(
stored
())
stored
.
set
(
"test"
)
XCTAssertEqual
(
stored
(),
"test"
)
stored
.
set
(
nil
)
XCTAssertNil
(
stored
())
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment