RandMyMod base on your own struct or class create one or a set of instance, which the variable's value in the instance is automatic randomized.

Overview

Alt text

RandMyMod is an IOS Native Framework helps you generate one or a set of variable base on your own model.

No matter your model is Class / Struct.

Alt text Alt text Alt text Alt text

Installation

  • Cocoapods
pod 'RandMyMod'

Basic Usage

  • Model must conform Codable

import RandMyMod
  • Create a Random Model

     let instance = MyStruct()
     RandMyMod<MyStruct>().randMe(baseOn: instance) { 
     	(newInstance) in
     	guard let newinstance = newInstance else { print("error"); return }
     }
  • Create a set of Random Model

     let instance = MyStruct()
     RandMyMod<MyStruct>().randUs(baseOn: instance) { 
     	(newInstanceArr) in
     	for newInstance in newInstanceArr {
     		guard let newinstance = newInstance else { print("error"); return }
     	}
     }
  • RandMyModDelegate

     public protocol RandMyModDelegate {
     	func countForArray(for key: String) -> Int
     	func shouldIgnore(for key: String, in Container: String) -> Bool
     	func catchError(with errorStr: String)
     	func specificRandType(for key: String, in Container: String, with seed: RandType) -> (()->Any)?
     }
  • Swift fake data generator

    vadymmarkov/Fakery : https://github.com/vadymmarkov/Fakery

Notice

  1. if the variable in class / stuct is Declared with 『 let 』 , rand mod will not change this variable's value.

    struct MyStruct {
    	let nochange: Int = 0
    }
    let mystruct = MyStruct()
    RandMyMod<MyStruct>().randMe(baseOn: mystruct) { (newstruct) in 
    	newstruct.nochange  // 0
    }
  2. if the variable in class / stuct is Declared with 『 Optional 』 and have no initial Value , rand mod will ignore this variable's value and keep it nil. (Mirror may resolve this issue, may fix in the future)

    struct MyStruct {
    	var opt: Int? = 0
    	var opt2: Int?
    }
    let mystruct = MyStruct()
    RandMyMod<MyStruct>().randMe(baseOn: mystruct) { (newstruct) in 
    	mystruct.opt  // 4242
    	mystruct.opt2 // nil
    }

Example

1. Stuct / Class with native variable type and no special specific:

	class Man: Codable {
    	var name: String = ""
    	var address: String = ""
    	var website: [String] = []
   	}
   	
   	let man = Man()
	RandMyMod<Man>().randMe(baseOn: man) { (newMan) in
    	guard let new = newMan else { return }
    	print(new.address) 	//mnxvpkalug
    	print(new.name) 	//iivjohpggb
    	print(new.website)	//["pbmsualvei", "vlqhlwpajf", "npgtxdmfyt"]
	}
	

2. Stuct / Class with native variable type and specific Rand Type:

struct Man: Codable {
    var name: String = ""
    var age: Int = 40
    var website: [String] = []
}

extension Man: RandMyModDelegate {
    
    func countForArray(for key: String) -> Int {
        switch key {
        case "website":
            return 3
        default:
            return 0
        }
    }
    
    func specificRandType(for key: String, in Container: String, with seed: RandType) -> (() -> Any)? {
        switch key {
        case "name":
            return { return seed.name.name() }
        case "age":
            return { return seed.number.randomInt(min: 1, max: 60)}
        case "website":
            return { return seed.internet.url() }
        default:
            return nil
        }   
    }
}

let man = Man()
RandMyMod<Man>().randMe(baseOn: man) { (newMan) in
    guard let new = newMan else { print("no"); return }
    print(new.age) 		//32
    print(new.name) 	//Lavada Krajcik
    print(new.website)	//["https://littleohara.name/johathangleason6379", "https://kautzerwunsch.biz/karleejones8880", "https://purdy.net/olivercorkery"]
}

3. Stuct / Class with own defined variable type and specific Rand Type:

struct Man: Codable {
    var name: String = ""
    var age: Int = 40
    var website: [String] = []
    var child: Child = Child()
}

struct Child: Codable {
    var name: String = "Baby" //Baby has no name yet.
    var age: Int = 2
    var toy: Toys = Toys()
}

class Toys: Codable {
    var weight: Double = 0.0
}

extension Man: RandMyModDelegate {
    
    func shouldIgnore(for key: String, in Container: String) -> Bool {
        switch (key, Container) {
        case ("name","child"):
            return true
        default:
            return false
        }
    }
  
    func specificRandType(for key: String, in Container: String, with seed: RandType) -> (() -> Any)? {
        switch (key, Container) {
        case ("age","child"):
            return { return seed.number.randomInt(min: 1, max: 6)}
        case ("weight",_):
            return { return seed.number.randomFloat() }
        default:
            return nil
        }
    }
}

let man = Man()
RandMyMod<Man>().randMe(baseOn: man) { (newMan) in
    guard let child = newMan?.child else { print("no"); return }
    print(child.name)	//Baby
    print(child.age)	//3
    print(child.toy.weight)	//392.807067871094
}

Distribution

Feel free to fork / pull request / open an issue.

You might also like...
A protocol that allows any class to be printed as if it were a struct or a JSON object.

ReflectedStringConvertible A protocol that extends CustomStringConvertible and uses reflection to add a detailed textual representation to any class.

Repository with base samples for playing HLS/DASH with CMAF video, across as many platforms as possible. Includes steps for encoding and packaging your own test content.

Video Everything Repository with minimal samples for playing HLS/DASH with CMAF video, across as many platforms as possible. Content and License All t

A swift PropertyWrapper to provide automatic NSView/UIView invalidation when the properties value changes.

A swift PropertyWrapper to provide automatic NSView/UIView invalidation when the properties value changes. It duplicates the @Invalidating propertyWrapper for build targets prior to macOS 12 and iOS 15.

Create your own faces for watchOS.  Customize the watch hands, layout, colors, and images.  Edit faces on your phone and switch them on the watch.
Create your own faces for watchOS. Customize the watch hands, layout, colors, and images. Edit faces on your phone and switch them on the watch.

AppleWatchFaces Design your own watch faces for the apple watch. They are not real watch faces, but a watchOS app running on the watch that tells you

🎚️ STDiscreteSlider – slider which allows user to choose value only from predefined set of data.
🎚️ STDiscreteSlider – slider which allows user to choose value only from predefined set of data.

STDiscreteSlider – slider which allows user to choose value only from predefined set of data. Slider may receive any types of options, you may pass set of integers or strings, or any other type. Written using SwiftUI.

TwilioChat_iOS - Twilio iOS SDK Implementaion Chat one-one Chat One-Many (Group)

TwilioChat_iOS - Twilio iOS SDK Implementaion Chat one-one Chat One-Many (Group) - Add Participant - Remove Participant Send Attachment Image Android - iOS Tested iOS - iOS Tested iOS - Android Tested React to Message, Delete a Message Read, Delivered, Sent Delete a Conversation Unread Messages Filter

🌳 Environment – a nicer, type-safe way of working with environment variables in Swift.

🌳 Environment Welcome to Environment – a nicer, type-safe way of working with environment variables in Swift. Usage Access Environment Variables The

Condense string literals into global variables.

Gettysburg This is an implementation of the SAX interface. API Documentation Documentation of the API can be found here: Gettysburg API A note on Char

Swift Programming Basics - Collections, Variables & Constants

Dicee What I learned in this module How to clone an existing Xcode project from GitHub. Create an app with behaviour and functionality. Create links b

Fridax enables you to read variables and intercept/hook functions in Xamarin/Mono JIT and AOT compiled iOS/Android applications.

Fridax is a Node package for dealing with Xamarin applications while using the Frida API. Goal • Installation • Usage • Examples • Issues • License Bu

Create an easy to peek SwiftUI View to showcase your own data, catalog, images, or anything you'd like.
Create an easy to peek SwiftUI View to showcase your own data, catalog, images, or anything you'd like.

Create an easy to peek SwiftUI View to showcase your own data, catalog, images, or anything you'd like.

📱 A simple wallpaper editor application for iPhone. Create your own wallpapers with a beautiful shelves.
📱 A simple wallpaper editor application for iPhone. Create your own wallpapers with a beautiful shelves.

iShelf A simple wallpaper editor application for iPhone. Create your own wallpapers with a beautiful shelves. 🎨 Demo 📸 Screenshots ✨ Features Lots o

Monaka convert custom struct to NSData.
Monaka convert custom struct to NSData.

Monaka Overview Monaka convert custom struct and fundamental values to NSData (also nested array and dictionary). Purpose You can persistent store of

🎨 View instance initializing sugar for Swift & UIKit
🎨 View instance initializing sugar for Swift & UIKit

🎨 View instance initializing sugar for Swift & UIKit

Xcode Plugin helps you find missing methods in your class header, protocols, and super class, also makes fast inserting.

FastStub-Xcode Life is short, why waste it on meaningless typing? What is it? A code generating feature borrowed from Android Studio. FastStub automat

Animate numeric value while setting new value to label
Animate numeric value while setting new value to label

NumericAnimatedLabel Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installati

🚀 Create XCFrameworks with ease! A Command Line Tool to create XCFramework for multiple platforms at one shot! The better way to deal with XCFrameworks for iOS, Mac Catalyst, tvOS, macOS, and watchOS.
🚀 Create XCFrameworks with ease! A Command Line Tool to create XCFramework for multiple platforms at one shot! The better way to deal with XCFrameworks for iOS, Mac Catalyst, tvOS, macOS, and watchOS.

Surmagic 🚀 Create XCFramework with ease! A Command Line Tool to create XCFramework for multiple platforms at one shot! The better way to deal with XC

A beautiful set of predefined colors and a set of color methods to make your iOS/OSX development life easier.
A beautiful set of predefined colors and a set of color methods to make your iOS/OSX development life easier.

Installation Drag the included Colours.h and Colours.m files into your project. They are located in the top-level directory. You can see a demo of how

Releases(v1.0)
Owner
郭介騵
Chinese iOS Developer, Check out my website for more
郭介騵
Monaka convert custom struct to NSData.

Monaka Overview Monaka convert custom struct and fundamental values to NSData (also nested array and dictionary). Purpose You can persistent store of

Naruki Chigira 22 Oct 29, 2020
A Distributed Value Store in Swift.

Impeller is a Distributed Value Store (DVS) written in Swift. It was inspired by successful Distributed Version Control Systems (DVCSes) like Git and

David Coyle 1 Jun 17, 2020
Swivl - A set of BLAS-accelerated linerar algebra structures and functions

Swivl - Swift Vector Library A set of BLAS-accelerated linerar algebra structure

null 0 Jan 19, 2022
Minimal edits from one collection to another

Changeset Changeset – pretty awesome little project — Joel Levin This is an attempt at implementing the solution outlined in Dave DeLong’s article, Ed

Joachim Bondo 807 Dec 5, 2022
Algorithm is a library of tools that is used to create intelligent applications.

Welcome to Algorithm Algorithm is a library of tools that is used to create intelligent applications. Features Probability Tools Expected Value Progra

Cosmicmind 820 Dec 9, 2022
Extension of Diffable API which allow not duplicate code and use less models. Included example for SideBar.

SPDiffable Apple's diffable API requerid models for each object type. If you want use it in many place, you pass many time to implemenet and get over

Ivan Vorobei 114 Jan 3, 2023
💻 LeetCode in your menu bar

LeetBar LeetCode in your menu bar Features Check the daily problem and view profile stats from your menu bar Get notified about the new daily problem

Marwan Hawari 45 Dec 18, 2022
A simple class that wraps the process of saving or loading a struct or class into a single file

EZFile This is a simple class that wraps the process of saving or loading a stru

null 7 May 16, 2022
Convert your own struct/enum to AnyObject easily.

AnyObjectConvertible Convert your own struct/enum to AnyObject easily. Sumally We can cast everything as AnyObject at Swift3.0 ?? So, we would not nee

tarunon 62 Feb 2, 2022
A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.

MJExtension A fast, convenient and nonintrusive conversion framework between JSON and model. 转换速度快、使用简单方便的字典转模型框架 ?? ✍??Release Notes: more details Co

M了个J 8.5k Jan 3, 2023