Swiftpack.co -  417-72KI/MockUserDefaults as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
417-72KI/MockUserDefaults
Mocking UserDefaults for tests
.package(url: "https://github.com/417-72KI/MockUserDefaults.git", from: "1.2.0")

MockUserDefaults

Build Status Platform Version GitHub release Carthage Compatible Swift Package Manager compatible Swift4.2 Swift5 GitHub license

MockUserDefaults is a simple replacement for NSUserDefaults/UserDefaults to make test easier.

Installation

CocoaPods

pod 'MockUserDefaults', '~> 1.2'

Carthage

github "417-72KI/MockUserDefaults" ~> 1.2

SwiftPM (Swift5 only)

.package(url: "https://github.com/417-72KI/MockUserDefaults.git", .upToNextMajor(from: "1.2.0")),

Usage

Objective-C

NSUserDefaults *userDefaults = [NSUserDefaults mockedUserDefaults];
[userDefaults setObject:@"string" forKey:@"key"];

XCTAssertEqualObjects([userDefaults objectForKey:@"key"], @"string");

Swift

let userDefaults: UserDefaults = .mocked
userDefaults.set("string", forKey: "key")

XCTAssertEqual(userDefaults.string(forKey: "key"), "string")

Demo

Dependencies

Tool

  • CocoaPods
    • Bundler
  • Carthage
    • Homebrew
  • XcodeGen
    • Mint
      • Homebrew
  • Fastlane
    • Bundler

Library

  • R.swift
  • RxSwift
  • RxDataSources
  • Nimble
  • Quick

Create project

First time

make init_demo_app

After the first time

make demo_app

Usage

  1. open MockUserDefaultsDemo.xcworkspace
  2. Build and run app (⌘+R) in iPhone / iPad Simulator
  3. Add any keys and values
  4. Run test (⌘+U) in same simulator
  5. Re-run app (⌘+R) in same simulator
  6. You can see that the app isn't affected by the test.

GitHub

link
Stars: 4
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Support Swift Package Manager
1 year ago

1.2.0

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API