-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from sonsongithub/improve-liveview
LiveView improvement
- Loading branch information
Showing
5 changed files
with
230 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// PlaygroundKeyValueStore.swift | ||
// sandbox | ||
// | ||
// Created by Yusuke Ito on 4/16/17. | ||
// Copyright © 2017 sonson. All rights reserved. | ||
// | ||
|
||
|
||
// PlaygroundKeyValueStore as UserDefautls for sandbox app | ||
|
||
#if os(iOS) | ||
import Foundation | ||
|
||
|
||
#if SANDBOX_APP | ||
// sandbox app | ||
internal enum PlaygroundValue { | ||
case array([PlaygroundValue]) | ||
case boolean(Bool) | ||
case data(Data) | ||
case date(Date) | ||
case dictionary([String: PlaygroundValue]) | ||
case floatingPoint(Double) | ||
case integer(Int) | ||
case string(String) | ||
} | ||
internal class PlaygroundKeyValueStore { | ||
static let current = PlaygroundKeyValueStore() | ||
private init() { | ||
|
||
} | ||
subscript(key: String) -> PlaygroundValue? { | ||
set { | ||
print("KeyValueStore setting \(newValue as Any) for \(key)") | ||
if let value = newValue { | ||
switch value { | ||
case .floatingPoint(let double): | ||
UserDefaults.standard.set(double, forKey: key) | ||
case .integer(let integer): | ||
UserDefaults.standard.set(integer, forKey: key) | ||
default: | ||
fatalError("Not implemented") | ||
} | ||
} else { | ||
UserDefaults.standard.removeObject(forKey: key) | ||
} | ||
} | ||
get { | ||
print("KeyValueStore getting for \(key)") | ||
guard let object = UserDefaults.standard.object(forKey: key) else { | ||
return nil | ||
} | ||
if let integer = object as? Int { | ||
return .integer(integer) | ||
} else if let double = object as? Double { | ||
return .floatingPoint(double) | ||
} else { | ||
fatalError("Not implemented") | ||
} | ||
} | ||
} | ||
} | ||
#else | ||
// playground | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters