Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ matrix:
- TVOS_SDK=appletvsimulator12.2
- WATCHOS_SIMULATOR='name=Apple Watch Series 4 - 44mm'
- WATCHOS_SDK=watchsimulator5.2
# - os: linux
# sudo: required
# dist: trusty
# name: Swift 5.0 compatibility
# env:
# - CACHE_NAME=LINUX_SWIFT5_0
# - SWIFT_VERSION=5.0-dev
# before_install:
# - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
# script:
# - swift test
- os: linux
sudo: required
dist: trusty
name: Swift 5.1 compatibility
env:
- CACHE_NAME=LINUX_SWIFT5_1
- SWIFT_VERSION=5.1
before_install:
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
script:
- TEST=1 swift test
- os: osx
osx_image: xcode10.1
name: Swift 4.2 compatibility
Expand All @@ -71,17 +71,17 @@ matrix:
- TVOS_SDK=appletvsimulator12.1
- WATCHOS_SIMULATOR='name=Apple Watch - 42mm'
- WATCHOS_SDK=watchsimulator5.1
# - os: linux
# sudo: required
# dist: trusty
# name: Swift 4.2 compatibility
# env:
# - CACHE_NAME=LINUX_SWIFT4_2
# - SWIFT_VERSION=4.2
# before_install:
# - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
# script:
# - swift test
- os: linux
sudo: required
dist: trusty
name: Swift 4.2 compatibility
env:
- CACHE_NAME=LINUX_SWIFT4_2
- SWIFT_VERSION=4.2
before_install:
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
script:
- TEST=1 swift test
- os: osx
osx_image: xcode10.1
name: Swift 4.1 compatibility
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### Next
* Added Swift for Linux support

### 5.1.0 (2020-12-14)
* Increase min deployment target to iOS 9.0 due to Xcode 12 requirements [@laevandus](https://github.com/laevandus)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SwiftyUserDefaults

[![Stake to support us](https://badge.devprotocol.xyz/0x5C7db549a025586DEc6667b3c0217e2e97f19033/descriptive)](https://stakes.social/0x5C7db549a025586DEc6667b3c0217e2e97f19033)
![Platforms](https://img.shields.io/badge/platforms-ios%20%7C%20osx%20%7C%20watchos%20%7C%20tvos-lightgrey.svg)
![Platforms](https://img.shields.io/badge/platforms-ios%20%7C%20osx%20%7C%20watchos%20%7C%20tvos%20%7C%20linux-lightgrey.svg)
[![CI Status](https://api.travis-ci.org/sunshinejr/SwiftyUserDefaults.svg?branch=master)](https://travis-ci.org/sunshinejr/SwiftyUserDefaults)
[![CocoaPods compatible](https://img.shields.io/badge/CocoaPods-compatible-4BC51D.svg?style=flat)](#cocoapods)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](#carthage)
Expand Down
2 changes: 1 addition & 1 deletion Sources/BuiltIns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension Data: DefaultsSerializable {
}

extension URL: DefaultsSerializable {
#if os(Linux)
#if !canImport(Darwin)
public static var _defaults: DefaultsKeyedArchiverBridge<URL> { return DefaultsKeyedArchiverBridge() }
#else
public static var _defaults: DefaultsUrlBridge { return DefaultsUrlBridge() }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Defaults+Observing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import Foundation

#if !os(Linux)
#if canImport(Darwin)

public extension DefaultsAdapter {

Expand Down
2 changes: 1 addition & 1 deletion Sources/DefaultsObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public protocol DefaultsDisposable {
func dispose()
}

#if !os(Linux)
#if canImport(Darwin)

public final class DefaultsObserver<T: DefaultsSerializable>: NSObject, DefaultsDisposable where T == T.T {

Expand Down
6 changes: 6 additions & 0 deletions Sources/PropertyWrappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
public struct SwiftyUserDefaultOptions: OptionSet {

public static let cached = SwiftyUserDefaultOptions(rawValue: 1 << 0)
#if canImport(Darwin)
public static let observed = SwiftyUserDefaultOptions(rawValue: 1 << 2)
#endif

public let rawValue: Int

Expand Down Expand Up @@ -62,22 +64,26 @@ public final class SwiftyUserDefault<T: DefaultsSerializable> where T.T == T {
self.key = adapter.keyStore[keyPath: keyPath]
self.options = options

#if canImport(Darwin)
if options.contains(.observed) {
observation = adapter.observe(key) { [weak self] update in
self?._value = update.newValue
}
}
#endif
}

public init(keyPath: KeyPath<DefaultsKeys, DefaultsKey<T>>, options: SwiftyUserDefaultOptions = []) {
self.key = Defaults.keyStore[keyPath: keyPath]
self.options = options

#if canImport(Darwin)
if options.contains(.observed) {
observation = Defaults.observe(key) { [weak self] update in
self?._value = update.newValue
}
}
#endif
}

deinit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ extension DefaultsSerializableSpec where Serializable.T: Equatable, Serializable
}

func testObserving() {
#if !os(Linux)
#if canImport(Darwin)
given("key-value observing") {
var defaults: DefaultsAdapter<FrogKeyStore<Serializable>>!
var observer: DefaultsDisposable?
Expand Down