Latest 3.0.1
Homepage https://github.com/GyazSquare/GSLSynthesizeSingleton
License MIT
Platforms ios 8.0, osx 10.6, tvos 9.0, watchos 2.0

Build Status

GSLSynthesizeSingleton is a simple macro to synthesize the methods for an Objective-C singleton class.

Requirements

  • Xcode 10.1 or later
  • Base SDK: iOS 12.1 / macOS 10.14.1 / watchOS 5.1 / tvOS 12.1 or later
  • Deployment Target: iOS 8.0 / OS X 10.6 / watchOS 2.0 / tvOS 9.0 or later

Installation

CocoaPods

Add the pod to your Podfile:

# ...

pod 'GSLSynthesizeSingleton'

Install the pod:

$ pod install

Source

Check out the source:

$ git clone https://github.com/GyazSquare/GSLSynthesizeSingleton.git

Copy GSLSynthesizeSingleton.h into your project.

Usage

  1. Declare a singleton class property or method in your header file.
  2. Add one macro in your source file.

XYZManager.h

@import Foundation;

NS_ASSUME_NONNULL_BEGIN

@interface XYZManager : NSObject

+ (instancetype)sharedManager;

// ...

@end

NS_ASSUME_NONNULL_END

Or if you use the class from Swift, you’d better declare as follows:

@import Foundation;

NS_ASSUME_NONNULL_BEGIN

@interface XYZManager : NSObject

@property (class, readonly) XYZManager *sharedManager;

- (instancetype)init NS_DESIGNATED_INITIALIZER OBJC_SWIFT_UNAVAILABLE("use 'aClass.shared' instead");

// ...

@end

NS_ASSUME_NONNULL_END

XYZManager.m

#import "GSLSynthesizeSingleton.h"
#import "XYZManager.h"

@implementation XYZManager

GSLSynthesizeSingleton(XYZ, Manager);

- (instancetype)init {
    self = [super init];
    if (self) {
        // ...
    }
    return self;
}

// ...

@end

License

This software is licensed under the MIT License.

See the LICENSE file for details.

Latest podspec

{
    "name": "GSLSynthesizeSingleton",
    "version": "3.0.1",
    "authors": "GyazSquare",
    "license": {
        "type": "MIT"
    },
    "homepage": "https://github.com/GyazSquare/GSLSynthesizeSingleton",
    "source": {
        "git": "https://github.com/GyazSquare/GSLSynthesizeSingleton.git",
        "tag": "v3.0.1"
    },
    "summary": "A simple macro for an Objective-C singleton class.",
    "platforms": {
        "ios": "8.0",
        "osx": "10.6",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "source_files": "GSLSynthesizeSingleton/*.{h,m}"
}

Pin It on Pinterest

Share This