diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..73fe78c --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,5 @@ +# Lines starting with '#' are comments. +# Each line is a file pattern followed by one or more owners. + +# These owners will be the default owners for everything in the repo. +* @JoeMatt diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..fa264dd --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,17 @@ +name: PublishDocumentation + +on: + release: + types: [published] + +jobs: + deploy_docs: + runs-on: macos-latest + steps: + - uses: actions/checkout@v1 + - name: Publish Jazzy Docs + uses: steven0351/publish-jazzy-docs@v1 + with: + personal_access_token: ${{ secrets.ACCESS_TOKEN }} + config: .jazzy.yaml + diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index df74c65..591ade0 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -2,7 +2,7 @@ name: Lint, build and test on: pull_request: - branches: [main] + branches: [main, develop] jobs: build: diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml new file mode 100644 index 0000000..1268b55 --- /dev/null +++ b/.github/workflows/rebase.yml @@ -0,0 +1,16 @@ +# Rebase PR branch when someone comments /rebase +on: + issue_comment: + types: [created] +name: Automatic Rebase +jobs: + rebase: + name: Rebase + if: contains(github.event.comment.body, '/rebase') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Automatic Rebase + uses: cirrus-actions/rebase@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml new file mode 100644 index 0000000..5a0bf60 --- /dev/null +++ b/.github/workflows/swift.yml @@ -0,0 +1,25 @@ +name: Swift PM + +on: + pull_request: + types: + - reopened + - opened + - synchronize + +jobs: + swift-pm: + + runs-on: macOS-latest + + steps: + - uses: actions/checkout@master + - name: Swift Setup + uses: YOCKOW/Action-setup-swift@v1 + with: + swift-version: '5.3.2' + - run: swift --version + - name: Resolve + run: swift package resolve + - name: Test + run: swift test diff --git a/.github/workflows/swiftlint.yml b/.github/workflows/swiftlint.yml new file mode 100644 index 0000000..a04f4e7 --- /dev/null +++ b/.github/workflows/swiftlint.yml @@ -0,0 +1,21 @@ +name: Swift Lint + +on: + pull_request: + paths: + - ".github/workflows/swiftlint.yml" + - ".swiftlint.yml" + - "Examples/**/*.swift" + - "Sources/**/*.swift" + - "Tests/**/*.swift" + +jobs: + swift-lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: GitHub Action for SwiftLint + uses: norio-nomura/action-swiftlint@3.2.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index fb05103..fe6af2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,12 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. -### [5.0.8](https://github.com/RxSwiftCommunity/RxRealm/branches/compare/v5.0.8%0Dv5.0.7) (2024-05-07) +## [5.1.0](https://github.com/RxSwiftCommunity/RxRealm/branches/compare/v5.1.0%0Dv5.0.7) (2024-05-07) -### [5.0.6](https://github.com/RxSwiftCommunity/RxRealm/branches/compare/v5.0.6%0Dv5.0.5) (2023-10-29) +### Fixes -### 5.0.5 (2022-03-09) +- Update SPM and CocoaPods packages for updated `Realm.swift` packaging linking -## [5.0.8](https://github.com/RxSwiftCommunity/RxRealm/branches/compare/v5.0.8%0Dv5.0.7) (2024-05-07) - -- Merge pull request #210 from trmquang93/main; override namespace Observable ## [5.0.7](https://github.com/RxSwiftCommunity/RxRealm/branches/compare/v5.0.7%0Dv5.0.6) (2024-03-08) diff --git a/Cartfile.resolved b/Cartfile.resolved index 1191c58..d102df0 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ github "ReactiveX/RxSwift" "6.5.0" -github "realm/realm-cocoa" "v10.21.1" +github "realm/realm-cocoa" "v10.28.6" diff --git a/Package.swift b/Package.swift index 91be267..54bb5fd 100644 --- a/Package.swift +++ b/Package.swift @@ -1,41 +1,41 @@ -// swift-tools-version:5.0 -// The swift-tools-version declares the minimum version of Swift required to build this package. +// swift-tools-version:5.7 import PackageDescription -let package = Package(name: "RxRealm", - platforms: [ - .macOS(.v10_10), .iOS(.v11), .tvOS(.v9), .watchOS(.v3) - ], - products: [ - // Products define the executables and libraries produced by a package, and make them visible to other packages. - .library(name: "RxRealm", - targets: ["RxRealm"]) - ], - - dependencies: [ - // Dependencies declare other packages that this package depends on. - .package(url: "https://github.com/realm/realm-swift.git", .upToNextMajor(from: "10.21.1")), - .package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.5.0")) - ], - - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. - .target(name: "RxRealm", - dependencies: [ - .product(name: "RxSwift", package: "RxSwift"), - .product(name: "RealmSwift", package: "Realm"), - .product(name: "RxCocoa", package: "RxSwift") - ], - path: "Sources"), - .testTarget(name: "RxRealmTests", - dependencies: [ - .byName(name: "RxRealm"), - .product(name: "RxSwift", package: "RxSwift"), - .product(name: "RxBlocking", package: "RxSwift"), - .product(name: "RealmSwift", package: "Realm"), - .product(name: "RxCocoa", package: "RxSwift") - ]) - ], - swiftLanguageVersions: [.v5]) +let package = Package( + name: "RxRealm", + platforms: [ + .macOS(.v10_13), .iOS(.v12), .tvOS(.v12), .watchOS(.v4) + ], + products: [ + .library( + name: "RxRealm", + type: .static, + targets: ["RxRealm"] + ), + .library( + name: "RxRealm-Dynamic", + type: .dynamic, + targets: ["RxRealm"] + ) + ], + dependencies: [ + .package(url: "https://github.com/realm/realm-swift.git", from: "10.50.0"), + .package(url: "https://github.com/ReactiveX/RxSwift.git", from: "6.7.1") + ], + targets: [ + .target( + name: "RxRealm", + dependencies: [ + .product(name: "RealmSwift", package: "realm-swift"), + .product(name: "RxSwift", package: "RxSwift"), + .product(name: "RxCocoa", package: "RxSwift") + ], + path: "Sources"), + .testTarget( + name: "RxRealmTests", + dependencies: ["RxRealm"] + ) + ], + swiftLanguageVersions: [.v5] +) diff --git a/README.md b/README.md index 17058a5..141027d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ This library is a thin wrapper around __RealmSwift__ ( [Realm Docs](https://real RxRealm can be used to create `Observable`s from objects of type `Results`, `List`, `LinkingObjects` or `AnyRealmCollection`. These types are typically used to load and observe object collections from the Realm Mobile Database. -##### `Observable.collection(from:synchronousStart:)` +### `Observable.collection(from:synchronousStart:)` + Emits an event each time the collection changes: ```swift @@ -38,7 +39,8 @@ Observable.collection(from: laps) The above prints out "X laps" each time a lap is added or removed from the database. If you set `synchronousStart` to `true` (the default value), the first element will be emitted synchronously - e.g. when you're binding UI it might not be possible for an asynchronous notification to come through. -##### `Observable.array(from:synchronousStart:)` +### `Observable.array(from:synchronousStart:)` + Upon each change fetches a snapshot of the Realm collection and converts it to an array value (for example if you want to use array methods on the collection): ```swift @@ -54,7 +56,8 @@ Observable.array(from: laps) }) ``` -##### `Observable.changeset(from:synchronousStart:)` +### `Observable.changeset(from:synchronousStart:)` + Emits every time the collection changes and provides the exact indexes that has been deleted, inserted or updated: ```swift @@ -76,7 +79,8 @@ Observable.changeset(from: laps) }) ``` -##### `Observable.arrayWithChangeset(from:synchronousStart:)` +### `Observable.arrayWithChangeset(from:synchronousStart:)` + Combines the result of `Observable.array(from:)` and `Observable.changeset(from:)` returning an `Observable, RealmChangeset?>` ```swift @@ -107,7 +111,7 @@ Observable.from(object: ticker) .map { ticker -> String in return "\(ticker.ticks) ticks" } - .bindTo(footer.rx.text) + .bind(to: footer.rx.text) ``` This API uses the [Realm object notifications](https://realm.io/news/realm-objc-swift-2.4/) under the hood to listen for changes. @@ -122,7 +126,7 @@ Observable.from(object: ticker, properties: ["name", "id", "family"]) ... ## Write transactions -##### `rx.add()` +### `rx.add()` Writing objects to **existing** realm reference. You can add newly created objects to a Realm that you already have initialized: @@ -136,7 +140,7 @@ Observable.from(messages) Be careful, this will retain your Realm until the `Observable` completes or errors out. -##### `Realm.rx.add()` +### `Realm.rx.add()` Writing to the default Realm. You can leave it to RxRealm to grab the default Realm on any thread your subscribe and write objects to it: @@ -147,7 +151,7 @@ Observable.from(messages) .subscribe(Realm.rx.add()) ``` -###### `Realm.rx.add(configuration:)` +### `Realm.rx.add(configuration:)` Writing to a **custom** Realm. If you want to switch threads and not use the default Realm, provide a `Realm.Configuration`. You an also provide an error handler for the observer to be called if either creating the realm reference or the write transaction raise an error: @@ -157,7 +161,7 @@ var config = Realm.Configuration() let messages = [Message("hello"), Message("world")] Observable.from(messages) - .observeOn( /* you can switch threads here */ ) + .observe(on: /* you can switch threads here */ ) .subscribe(Realm.rx.add(configuration: config, onError: {elements, error in if let elements = elements { print("Error \(error.localizedDescription) while saving objects \(String(describing: elements))") @@ -173,7 +177,7 @@ If you want to create a Realm on a different thread manually, allowing you to ha let messages = [Message("hello"), Message("world")] Observable.from(messages) - .observeOn( /* you can switch threads here */ ) + .observe(on: /* you can switch threads here */ ) .subscribe(onNext: {messages in let realm = try! Realm() try! realm.write { @@ -182,7 +186,7 @@ Observable.from(messages) }) ``` -##### `rx.delete()` +### `rx.delete()` Deleting object(s) from an existing realm reference: @@ -195,7 +199,7 @@ Observable.from(messages) Be careful, this will retain your realm until the `Observable` completes or errors out. -##### `Realm.rx.delete()` +### `Realm.rx.delete()` Deleting from the object's realm automatically. You can leave it to RxRealm to grab the Realm from the first object and use it: @@ -208,21 +212,21 @@ Observable.from(someCollectionOfPersistedObjects) RxRealm does not depend on UIKit/Cocoa and it doesn't provide built-in way to bind Realm collections to UI components. -#### a) Non-animated binding +### a) Non-animated binding -You can use the built-in RxCocoa `bindTo(_:)` method, which will automatically drive your table view from your Realm results: +You can use the built-in RxCocoa `bind(to:)` method, which will automatically drive your table view from your Realm results: ```swift Observable.from( [Realm collection] ) - .bindTo(tableView.rx.items) {tv, ip, element in + .bind(to: tableView.rx.items) {tv, ip, element in let cell = tv.dequeueReusableCell(withIdentifier: "Cell")! cell.textLabel?.text = element.text return cell } - .addDisposableTo(bag) + .disposed(by: bag) ``` -#### b) Animated binding with RxRealmDataSources +### b) Animated binding with RxRealmDataSources The separate library [RxRealmDataSources](https://github.com/RxSwiftCommunity/RxRealmDataSources) mimics the default data sources library behavior for RxSwift. @@ -242,8 +246,8 @@ let laps = Observable.changeset(from: lapsList) // bind to table view laps - .bindTo(tableView.rx.realmChanges(dataSource)) - .addDisposableTo(bag) + .bind(to: tableView.rx.realmChanges(dataSource)) + .disposed(by: bag) ``` The data source will reflect all changes via animations to the table view: @@ -262,7 +266,7 @@ Further you're welcome to peak into the __RxRealmTests__ folder of the example a This library depends on both __RxSwift__ and __RealmSwift__ 1.0+. -#### CocoaPods +### CocoaPods RxRealm requires CocoaPods 1.1.x or higher. @@ -272,7 +276,7 @@ RxRealm is available through [CocoaPods](http://cocoapods.org). To install it, s pod "RxRealm" ``` -#### Carthage +### Carthage To integrate RxRealm into your Xcode project using Carthage, specify it in your `Cartfile`: @@ -282,7 +286,7 @@ github "RxSwiftCommunity/RxRealm" Run `carthage update` to build the framework and drag the built `RxRealm.framework` into your Xcode project. -#### Swift Package Manager +### Swift Package Manager In your Package.swift: @@ -290,7 +294,7 @@ In your Package.swift: let package = Package( name: "Example", dependencies: [ - .package(url: "https://github.com/RxSwiftCommunity/RxRealm.git", from: "1.0.1") + .package(url: "https://github.com/RxSwiftCommunity/RxRealm.git", from: "5.0.4") ], targets: [ .target(name: "Example", dependencies: ["RxRealm"]) @@ -304,6 +308,8 @@ let package = Package( ## License -This library belongs to _RxSwiftCommunity_. Maintainer is [Marin Todorov](https://github.com/icanzilb). +This library belongs to _RxSwiftCommunity_. +Maintainer is [Joe Mattiello](https://github.com/JoeMatt). +Previous maintainer was [Marin Todorov](https://github.com/icanzilb). RxRealm is available under the MIT license. See the LICENSE file for more info. diff --git a/RxRealm.podspec b/RxRealm.podspec index f60701d..806c5e7 100644 --- a/RxRealm.podspec +++ b/RxRealm.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "RxRealm" # Version to always follow latest tag, with fallback to major - s.version = "5.0.8" + s.version = "5.1.0" s.license = "MIT" s.description = <<-DESC This is an Rx extension that provides an easy and straight-forward way diff --git a/Sources/RxRealm/RxRealm.swift b/Sources/RxRealm/RxRealm.swift index 326bb3a..8dc2eae 100644 --- a/Sources/RxRealm/RxRealm.swift +++ b/Sources/RxRealm/RxRealm.swift @@ -10,8 +10,6 @@ import Foundation import RealmSwift import RxSwift -public typealias Observable = RxSwift.Observable - public enum RxRealmError: Error { case objectDeleted case unknown