Skip to content

Commit

Permalink
Release 1.0.0 (#1)
Browse files Browse the repository at this point in the history
* Implement `objects-factory` package

* Update `workflows`

* Update `README.md`

* Update `CHANGELOG.md`

* Add `CodeCov` badge
  • Loading branch information
ns-vasilev authored Oct 15, 2023
1 parent 230ad44 commit be01680
Show file tree
Hide file tree
Showing 15 changed files with 531 additions and 1 deletion.
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: "objects-factory"

on:
push:
branches:
- main
- dev
pull_request:
paths:
- '.swiftlint.yml'
branches:
- main
- dev

concurrency:
group: ci
cancel-in-progress: true

jobs:
SwiftLint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: GitHub Action for SwiftLint
uses: norio-nomura/[email protected]
with:
args: --strict
env:
DIFF_BASE: ${{ github.base_ref }}
Latest:
name: Test (iOS)
runs-on: macOS-12
env:
DEVELOPER_DIR: "/Applications/Xcode_14.1.app/Contents/Developer"
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- destination: "OS=16.1,name=iPhone 14 Pro"
name: "iOS"
scheme: "ObjectsFactory"
sdk: iphonesimulator
steps:
- uses: actions/checkout@v3
- name: ${{ matrix.name }}
run: xcodebuild test -scheme "${{ matrix.scheme }}" -destination "${{ matrix.destination }}" clean -enableCodeCoverage YES -resultBundlePath "./${{ matrix.sdk }}.xcresult"
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
xcode: true
xcode_archive_path: "./${{ matrix.sdk }}.xcresult"
135 changes: 135 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
excluded:
- Tests
- Package.swift
- .build

# Rules

disabled_rules:
- trailing_comma
- todo
- opening_brace

opt_in_rules: # some rules are only opt-in
- anyobject_protocol
- array_init
- attributes
- closure_body_length
- closure_end_indentation
- closure_spacing
- collection_alignment
- conditional_returns_on_newline
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- convenience_type
- discouraged_object_literal
- discouraged_optional_boolean
- empty_collection_literal
- empty_count
- empty_string
- empty_xctest_method
- enum_case_associated_values_count
- explicit_init
- fallthrough
- fatal_error_message
- file_name
- file_types_order
- first_where
- flatmap_over_map_reduce
- force_unwrapping
- ibinspectable_in_extension
- identical_operands
- implicit_return
- inert_defer
- joined_default_parameter
- last_where
- legacy_multiple
- legacy_random
- literal_expression_end_indentation
- lower_acl_than_parent
- multiline_arguments
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
- multiline_parameters_brackets
- no_space_in_method_call
- operator_usage_whitespace
- optional_enum_case_matching
- orphaned_doc_comment
- overridden_super_call
- override_in_extension
- pattern_matching_keywords
- prefer_self_type_over_type_of_self
- prefer_zero_over_explicit_init
- prefixed_toplevel_constant
- private_action
- prohibited_super_call
- quick_discouraged_call
- quick_discouraged_focused_test
- quick_discouraged_pending_test
- reduce_into
- redundant_nil_coalescing
- redundant_objc_attribute
- redundant_type_annotation
- required_enum_case
- single_test_class
- sorted_first_last
- sorted_imports
- static_operator
- strict_fileprivate
- switch_case_on_newline
- toggle_bool
- unavailable_function
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- xct_specific_matcher
- yoda_condition

force_cast: warning
force_try: warning

identifier_name:
excluded:
- id
- URL

analyzer_rules:
- unused_import
- unused_declaration

line_length:
warning: 130
error: 200

type_body_length:
warning: 300
error: 400

file_length:
warning: 500
error: 1200

function_body_length:
warning: 30
error: 50

large_tuple:
error: 3

nesting:
type_level:
warning: 2
statement_level:
warning: 10


type_name:
max_length:
warning: 40
error: 50
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.

#### 1.x Releases
- `1.0.x` Releases - [1.0.0](#100)

## [1.0.0](https://github.com/space-code/objects-factory/releases/tag/1.0.0)
Released on 2023-10-15.

#### Added
- Initial release of `objects-factory`.
- Added by [Nikita Vasilev](https://github.com/nik3212).
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
all: bootstrap

bootstrap: hook
mint bootstrap

hook:
ln -sf ../../hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

mint:
mint bootstrap

lint:
mint run swiftlint

fmt:
mint run swiftformat Sources Tests

.PHONY: all bootstrap hook mint lint fmt
2 changes: 2 additions & 0 deletions Mintfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nicklockwood/[email protected]
realm/[email protected]
27 changes: 27 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ObjectsFactory",
platforms: [.iOS(.v13)],
products: [
.library(name: "ObjectsFactory", targets: ["ObjectsFactory"]),
],
dependencies: [],
targets: [
.target(
name: "ObjectsFactory",
dependencies: ["ObjectsFactoryObjC"]
),
.target(
name: "ObjectsFactoryObjC",
dependencies: []
),
.testTarget(
name: "ObjectsFactoryTests",
dependencies: ["ObjectsFactory"]
),
]
)
76 changes: 75 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,75 @@
# objects-factory
<h1 align="center" style="margin-top: 0px;">objects-factory</h1>

<p align="center">
<a href="https://github.com/space-code/objects-factory/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/space-code/objects-factory?style=flat"></a>
<a href="https://developer.apple.com/swift"><img alt="5.7" src="https://img.shields.io/badge/language-Swift5.7-orange.svg"/></a>
<a href="https://github.com/space-code/objects-factory"><img alt="CI" src="https://github.com/space-code/objects-factory/actions/workflows/ci.yml/badge.svg?branch=main"></a>
<a href="https://github.com/apple/swift-package-manager" alt="objects-factory on Swift Package Manager" title="objects-factory on Swift Package Manager"><img src="https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg" /></a>
<a href="https://codecov.io/gh/space-code/objects-factory"><img alt="CodeCov" src="https://codecov.io/gh/space-code/objects-factory/graph/badge.svg?token=NSI8N7Q9JB"></a>
</p>

## Description
`objects-factory` helps to create objects for unit tests that have a private initializer.

- [Usage](#usage)
- [Requirements](#requirements)
- [Installation](#installation)
- [Communication](#communication)
- [Contributing](#contributing)
- [Author](#author)
- [License](#license)

## Usage

⚠️ It should only be used for testing purposes, like for unit-testing. ⚠️

It's important that the class you want to instantiate is a subclass of `NSObject`.

```swift
import ObjectsFactory

do {
let session = try ObjectsFactory.create(UIScene.self)
let _ = try ObjectsFactory.create(UIWindowScene.self, properties: ["session": session])
} catch {
// Handle an error here
}
```

## Requirements
- iOS 13.0+
- Xcode 14.0
- Swift 5.7

## Installation
### Swift Package Manager

The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but `objects-factory` does support its use on supported platforms.

Once you have your Swift package set up, adding `objects-factory` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.

```swift
dependencies: [
.package(url: "https://github.com/space-code/objects-factory.git", .upToNextMajor(from: "1.0.0"))
]
```

## Communication
- If you **found a bug**, open an issue.
- If you **have a feature request**, open an issue.
- If you **want to contribute**, submit a pull request.

## Contributing
Bootstrapping development environment

```
make bootstrap
```

Please feel free to help out with this project! If you see something that could be made better or want a new feature, open up an issue or send a Pull Request!

## Author
Nikita Vasilev, [email protected]

## License
objects-factory is available under the MIT license. See the LICENSE file for more info.
21 changes: 21 additions & 0 deletions Sources/ObjectsFactory/Classes/ObjectsFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// objects-factory
// Copyright © 2023 Space Code. All rights reserved.
//

import ObjectsFactoryObjC

public typealias ObjectsFactory = ObjectsFactoryObjC.ObjectsFactory

public extension ObjectsFactory {
static func create<T: AnyObject>(_ classType: T.Type, properties: [String: Any] = [:]) throws -> T {
if let instance = ObjectsFactory.createInstance(classType, properties: properties) as? T {
return instance
}
throw NSError(
domain: "ObjectsFactory",
code: 1,
userInfo: [NSLocalizedDescriptionKey: "Cannot create an instance of \(classType)"]
)
}
}
6 changes: 6 additions & 0 deletions Sources/ObjectsFactoryObjC/Internal/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
framework module ObjectsFactory {
umbrella header "ObjectsFactory.h"

export *
module * { export * }
}
Loading

0 comments on commit be01680

Please sign in to comment.