Skip to content

Commit

Permalink
initial project commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lspaczynski committed Dec 16, 2021
1 parent 9ed4e24 commit 6288766
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 88 deletions.
93 changes: 5 additions & 88 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,90 +1,7 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
70 changes: 70 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"object": {
"pins": [
{
"package": "Action",
"repositoryURL": "https://github.com/RxSwiftCommunity/Action.git",
"state": {
"branch": null,
"revision": "55f5da064fd66cb09acde22cbbb744fe7f6355aa",
"version": "5.0.0"
}
},
{
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "35f9e770f54ce62dd8526470f14c6e137cef3eea",
"version": "2.1.1"
}
},
{
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "c21f7bab5ca8eee0a9998bbd17ca1d0eb45d4688",
"version": "2.1.0"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "c93f16c25af5770f0d3e6af27c9634640946b068",
"version": "9.2.1"
}
},
{
"package": "RxAppState",
"repositoryURL": "https://github.com/pixeldock/RxAppState.git",
"state": {
"branch": null,
"revision": "956f438ea16481c1bd9a8ca3bc169af7435aaf0b",
"version": "1.7.1"
}
},
{
"package": "RxSwift",
"repositoryURL": "https://github.com/ReactiveX/RxSwift.git",
"state": {
"branch": null,
"revision": "7c17a6ccca06b5c107cfa4284e634562ddaf5951",
"version": "6.2.0"
}
},
{
"package": "RxSwiftExt",
"repositoryURL": "https://github.com/RxSwiftCommunity/RxSwiftExt.git",
"state": {
"branch": null,
"revision": "a42af9caeab63f2dbde318f1f3dc424f05871a37",
"version": "6.1.0"
}
}
]
},
"version": 1
}
45 changes: 45 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ShowcaseExtensions",
platforms: [.iOS(.v13)],
products: [
.library(
name: "ShowcaseExtensions",
targets: ["ShowcaseExtensions"]),
],
dependencies: [
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.2.0")),
.package(url: "https://github.com/RxSwiftCommunity/RxSwiftExt.git", .upToNextMajor(from: "6.1.0")),
.package(url: "https://github.com/pixeldock/RxAppState.git", .upToNextMajor(from: "1.7.1")),
.package(url: "https://github.com/RxSwiftCommunity/Action.git", .upToNextMajor(from: "5.0.0")),
.package(url: "https://github.com/Quick/Nimble.git", .upToNextMajor(from: "9.2.1"))
],
targets: [
.target(
name: "ShowcaseExtensions",
dependencies: [
.product(name: "RxSwift", package: "RxSwift"),
.product(name: "RxCocoa", package: "RxSwift"),
"RxSwiftExt",
"RxAppState",
"Action"
]),
.testTarget(
name: "ShowcaseExtensionsTests",
dependencies: [
"ShowcaseExtensions",
.product(name: "RxSwift", package: "RxSwift"),
.product(name: "RxCocoa", package: "RxSwift"),
.product(name: "RxBlocking", package: "RxSwift"),
.product(name: "RxTest", package: "RxSwift"),
"RxSwiftExt",
"RxAppState",
"Action",
"Nimble"
]),
]
)
34 changes: 34 additions & 0 deletions Sources/ShowcaseExtensions/NSAttributedString+RTF.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// NSAttributedString+RTF.swift
// ShowcaseData
//
// Created by Lukasz Spaczynski on 24/11/2021.
//

import Foundation

#if canImport(UIKit)

import UIKit

public extension NSAttributedString {
static func rtf(url: URL) throws -> NSAttributedString {
let options = [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.rtf]
return try NSAttributedString(url: url, options: options, documentAttributes: nil)
}
}

public extension NSAttributedString {
func replacing(placeholder: String, with valueString: String) -> NSAttributedString {
if let range = string.range(of: placeholder) {
let nsRange = NSRange(range, in: string)
let mutableText = NSMutableAttributedString(attributedString: self)
mutableText.replaceCharacters(in: nsRange, with: valueString)
return mutableText as NSAttributedString
}
return self
}
}

#endif

48 changes: 48 additions & 0 deletions Sources/ShowcaseExtensions/Result.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Result.swift
// ShowcaseApp
//
// Created by Lukasz Spaczynski on 24/11/2021.
//

import Foundation
import RxSwift

public extension Result {
func asObservable() -> Observable<Success> {
switch self {
case let .success(value):
return .just(value)
case let .failure(error):
return .error(error)
}
}
}

public extension Result {
var value: Success? {
switch self {
case let .success(s):
return s
default:
return nil
}
}

var error: Failure? {
switch self {
case let .failure(e):
return e
default:
return nil
}
}

var hasError: Bool {
error != nil
}

var hasValue: Bool {
value != nil
}
}
74 changes: 74 additions & 0 deletions Tests/ShowcaseExtensionsTests/ResultTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// File.swift
//
//
// Created by Lukasz Spaczynski on 16/12/2021.
//

import Foundation
import Nimble
import XCTest
import RxSwift
import RxBlocking

@testable import ShowcaseExtensions

final class ResultTests: XCTestCase {

private enum DummyError: Error {
case dummy
}

func testValue() {
// GIVEN
let sut = Result<String, Error>.success("test")

//THEN
expect(sut.value).toNot(beNil())
expect(sut.error).to(beNil())
expect(sut.hasValue).to(beTrue())
expect(sut.hasError).to(beFalse())
}

func testError() {
// GIVEN
let sut = Result<String, DummyError>.failure(.dummy)

//THEN
expect(sut.value).to(beNil())
expect(sut.error).toNot(beNil())
expect(sut.hasValue).to(beFalse())
expect(sut.hasError).to(beTrue())
}

func testObservableValue() throws {
// GIVEN
let sut = Result<String, Error>.success("test")

// WHEN
let observable = sut.asObservable()
let result = try observable
.toBlocking()
.first()

// THEN
expect(result).toNot(beNil())
expect(result).to(equal("test"))
}

func testObservableError() {
// GIVEN
let sut = Result<String, DummyError>.failure(.dummy)

// WHEN
let observable = sut.asObservable()
do {
_ = try observable
.toBlocking()
.first()
} catch {
// THEN
expect(error).to(beAKindOf(DummyError.self))
}
}
}

0 comments on commit 6288766

Please sign in to comment.