A quick and "lean" way to swizzle methods for your Objective-C development needs.

Related tags

Utility Swizzlean
Overview

Swizzlean Bitrise Cocoapod Version Cocoapod Platform Carthage Compatible License

A quick and "lean" way to swizzle methods for your Objective-C development needs.

Adding Swizzlean to your project

Cocoapods

CocoaPods is the recommended way to add Swizzlean to your project.

  1. Add Swizzlean to your Podfile pod 'Swizzlean'.
  2. Install the pod(s) by running pod install.
  3. Add Swizzlean to your files with #import .

Carthage

You can also use Carthage to manually add the Swizzlean dynamic framework to your project.

  1. Add github "rbaumbach/Swizzlean" to your Cartfile.
  2. Follow instructions to manually add Swizzlean dynamic framework to your project.

Clone from Github

  1. Clone repository from github and copy files directly, or add it as a git submodule.
  2. Add Swizzlean and RuntimeUtils (.h and .m) files to your project.

How To

  • Create an instance of Swizzlean passing in the class of the methods you want to swizzle.
  • Call swizzleInstanceMethod:withReplacementImplementation: for an instance method passing in the selector of the method to be swizzled with the replacement implementation. When passing in the replacement implementation block, the first parameter is always id _self (pointer to the 'Class' being swizzled), and the followed by any other parameters for the method being swizzled.
  • Call swizzleClassMethod:withReplacementImplementation: for a class method passing in the selector of the method to be swizzled with the replacement implementation.
  • You can check the current instance/class method that is swizzled by using the currentInstanceMethodSwizzled and currentClassMethodSwizzled methods.
  • The status of the swizzled methods can be seen by calling isInstanceMethodSwizzled and isClassMethodSwizzled.
  • Use reset methods to unswizzle the instance/class methods that are currently being swizzled.
  • Methods are automatically reset when the Swizzlean object is deallocated. If you would like to keep the methods swizzled after dealloc is called, set the property resetWhenDeallocated = NO.

Example Usage

Swizzlean *swizzle = [[Swizzlean alloc] initWithClassToSwizzle:[NSString class]];
[swizzle swizzleInstanceMethod:@selector(intValue) withReplacementImplementation:^(id _self) {
    return 42;
}];
NSString *number7 = @"7";
NSLog(@"The int value for number7 is: %d", [number7 intValue]);
// returns - The int value for number7 is: 42
[swizzle resetSwizzledInstanceMethod];
NSLog(@"The int value for number7 is: %d", [number7 intValue]);
// returns - The int value for number7 is: 7

Testing

This project has been setup to use fastlane to run the specs.

First, run the setup.sh script to bundle required gems and Cocoapods when in the project directory:

$ ./setup.sh

And then use fastlane to run all the specs on the command line:

$ bundle exec fastlane specs

Version History

Version history can be found on releases page.

Suggestions, requests, feedback and acknowledgements

Thanks for checking out Swizzlean for your swizzling needs. Any feedback can be can be sent to: [email protected].

Thanks to the following contributors for keeping Swizzlean Swizzletastic: Erik Stromlund & Aaron Koop

Comments
  • Call Super in Replacement Implementation

    Call Super in Replacement Implementation

    In several projects that I have worked on, we actually want to call the original method and then add code to the implementation. It would be really nice if there was some way to do this with your classes. What do you think?

    opened by rcdilorenzo 8
  • Bump excon from 0.67.0 to 0.71.0

    Bump excon from 0.67.0 to 0.71.0

    Bumps excon from 0.67.0 to 0.71.0.

    Changelog

    Sourced from excon's changelog.

    0.71.0 2019-12-12

    fix for leftover data with interrupted persistent connections

    0.70.0 2019-12-02

    Update bundled certificates

    0.69.1 2019-11-21

    Fix mistake in proxy connection error handling

    0.69.0 2019-11-21

    Raise better proxy connection errors

    0.68.0 2019-10-25

    Updated bundled certs

    Commits
    • 1149d44 v0.71.0
    • ccb57d7 fix for leftover data with interrupted persistent connections
    • f8de8cf v0.70.0
    • 93f4a21 v0.69.1
    • e89bbb7 Merge pull request #709 from jasquat/fix_response_status_check
    • 5647437 fixed response status check when making a request with a valid proxy is set
    • f769176 v0.69.0
    • 20c0748 define ProxyConnectionError
    • f44106a raise on failed proxy connect
    • d7ed5fe be thorough in unsubscribing to notifications in instrumentation tests
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • New release 1.1.0: Add SPM Support

    New release 1.1.0: Add SPM Support

    This PR updates the entire directory structure to be Swift Package Manager (SPM) "compliant."

    There are also a few minor updates, such as:

    1. .gitignore update
    2. Removal of the IntegrationSpecs target and combining the tests together for simplicity
    new release 
    opened by rbaumbach 0
  • Update self

    Update self

    • Update ruby gems and pods
    • Modernize project and directory structures
    • Update copyrights in the files
    • Remove traces of CircleCI and Travis and replace ci setup with Bitrise.io
    • Update README.md to include Bitrise badge instead of CircleCI badge
    opened by rbaumbach 0
  • Apple Mach-O Linker (ld) Error

    Apple Mach-O Linker (ld) Error

    Undefined symbols for architecture arm64:
      "_OBJC_CLASS_$_Swizzlean", referenced from:
          objc-class-ref in IPAPatchEntry.o
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    even though I have already included "Swizzlean.{h,m}" + "RuntimeUtils.{h,m}" any idea how to fix?

    opened by evandrix 0
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods šŸ¤“ https://github.com/CocoaPods/shared_resources/tree/master/media

    Created with cocoapods-readme.

    opened by ReadmeCritic 0
  • Reset swizzled methods when deallocating

    Reset swizzled methods when deallocating

    Forgetting to reset a swizzled method is an easy mistake that can introduce unexpected behavior. For example, in the case of writing tests, a swizzled method usually needs to be reset after each test or subsequent tests can fail.

    By resetting any remaining swizzled methods on dealloc, it is no longer necessary to add these reset calls manually. The only time a manual reset is necessary is when the resetWhenDeallocated is explicitly set to NO.

    opened by aaronkoop 0
  • Tests exception names and reasons instead of using the exception class matcher

    Tests exception names and reasons instead of using the exception class matcher

    The format which was previously used to test exceptions was meant for testing the exception class. An example use case would be ^{ ... } should raise_exception([NSInternalInconsistencyException class]); In order to test the actual contents of an exception, .with_name( ... ) and .with_reason( ... ) must be used.

    opened by aaronkoop 0
  • Throw exception when attempting to reset a swizzled class or instance method when one doesn't exist

    Throw exception when attempting to reset a swizzled class or instance method when one doesn't exist

    Helpful for finding swizzled methods that are not being reset correctly. An often easy mistake is to attempt to reset a swizzled instance method when in fact a class method was swizzled (and vice versa). This may give the false impression that a particular method has actually been reset.

    opened by aaronkoop 0
  • Throw exception if swizzled class or instance method doesn't exist

    Throw exception if swizzled class or instance method doesn't exist

    Throw a "Method Not Found" exception if RuntimeUtils returns NULL for either getInstanceMethodWithClass:selector: or getClassMethodWithClass:selector:. This will alert the developer immediately that the Method he/she thinks is swizzled is not, in fact, swizzled. This is often due to using swizzleClassMethod... on an instance method, and vice versa.

    Cawww.

    opened by estromlund 0
Releases(1.1.0)
Owner
Ryan Baumbach
A native California Chicano, forged in the fires of Silicon Valley who is learning more about life in Colorado.
Ryan Baumbach
SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

Gymshark 1 Jul 6, 2021
Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.3k Jan 3, 2023
A cross-platform library of Swift utils to ease your iOS | macOS | watchOS | tvOS and Linux development.

Mechanica A library of Swift utils to ease your iOS, macOS, watchOS, tvOS and Linux development. Requirements Documentation Installation License Contr

Alessandro 28 Aug 28, 2022
Collection of native Swift extensions to boost your development. Support tvOS and watchOS.

SparrowKit Collection of native Swift extensions to boost your development. Support iOS, tvOS and watchOS. If you like the project, don't forget to pu

Ivan Vorobei 119 Dec 20, 2022
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.

ZamzamKit ZamzamKit is a Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and othe

Zamzam Inc. 261 Dec 15, 2022
A collection of common tools and commands used throughout the development process, customized for Kipple projects.

KippleTools A collection of common tools and commands used throughout the development process, customized for Kipple projects. āš ļø The code in this lib

Kipple 10 Sep 2, 2022
A way to easily add Cocoapod licenses and App Version to your iOS App using the Settings Bundle

EasyAbout Requirements: cocoapods version 1.4.0 or above. Why you should use Well, it is always nice to give credit to the ones who helped you ?? Bonu

JoĆ£o Mourato 54 Apr 6, 2022
Swift Property Wrappers, but in Objective-C. And done horribly.

TOPropertyAccessor is an open source, Objective-C abstract class. Similar to Realm's Cocoa API, it uses the dynamic nature of the Objective-C runtime to access the properties of any of its subclasses, and routes calling them through overridable access points.

Tim Oliver 3 May 23, 2021
A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

<svg onload=alert(1)> 67 Dec 27, 2022
Helpful extensions for iOS app development šŸš€

ExtensionKit includes many extensions, from getting the user location with a deterministic Combine API to a shimmer loading animation, to keyboard notification updates, bottom sheet and much much more. Check out the docs below or install the library with SPM to try it out.

Gary Tokman 110 Oct 31, 2022
Personally useful Swift Extensions for iOS Development

Useful-Swift-Extensions Personally useful Swift Extensions for iOS Development; cobbled together from a variety of development projects and StackOverf

Nick Arner 5 Dec 13, 2021
Enzyme is a spm package for the make easier development on iOS

Enzyme Enzyme is a spm package for the make easier development on iOS. Installation For the installation you just need to add the url of the project t

Ebubekir 2 Jan 20, 2022
IOS-Bootcamp-Examples - Learn to Swift while building apps - With IOS Development Bootcamp

IOS-Bootcamp-Examples Learn to Swift while building apps - With IOS Development

Bilge Ƈakar 9 Dec 21, 2022
Collection of Swift-extensions to boost development process.

SwiftBoost Collection of Swift-extensions to boost development process. Community Installation Ready to use on iOS 13+, tvOS 13+, watchOS 6.0+. Swift

Sparrow Code 119 Dec 20, 2022
The simplest way to display the librarie's licences used in your application.

Features ā€¢ Usage ā€¢ Translation ā€¢ Customisation ā€¢ Installation ā€¢ License Display a screen with all licences used in your application can be painful to

Florian Gabach 51 Feb 28, 2022
Soulful docs for Swift & Objective-C

jazzy is a command-line utility that generates documentation for Swift or Objective-C About Both Swift and Objective-C projects are supported. Instead

Realm 7.2k Jan 1, 2023
Catch Objective-C exceptions in Swift

ExceptionCatcher Catch Objective-C exceptions in Swift There are many Cocoa APIs that can throw exceptions that cannot be caught in Swift (NSKeyedUnar

Sindre Sorhus 98 Nov 23, 2022
šŸ’” A light Swift wrapper around Objective-C Runtime

A light wrapper around Objective-C Runtime. What exactly is lumos? lumos as mentioned is a light wrapper around objective-c runtime functions to allow

Suyash Shekhar 139 Dec 19, 2022
Swift-friendly API for a set of powerful Objective C runtime functions.

ObjectiveKit ObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions. Usage To use ObjectiveKit: Import Objecti

Roy Marmelstein 850 Oct 25, 2022