All Projects → macmade → Objcxx

macmade / Objcxx

Projects that are alternatives of or similar to Objcxx

OperationPlus
NSOperation's missing pieces
Stars: ✭ 119 (+120.37%)
Mutual labels:  foundation, cocoa
Pyupdater
Pyinstaller auto-update library
Stars: ✭ 300 (+455.56%)
Mutual labels:  wrapper, framework
Objective-CPP
C++ compatibility library for Objective-C - Objective-CPP is a library intended to ease software development using Objective-C++. It declares categories on Objective-C classes, to work with the STL C++ types, such as std::string, std::vector, etc.
Stars: ✭ 37 (-31.48%)
Mutual labels:  foundation, interoperability
ProcessEnv
Capture the shell environment of a Foundation app
Stars: ✭ 16 (-70.37%)
Mutual labels:  foundation, cocoa
Alicerce
A base for iOS Applications made with ❤️ by Mindera 🤠
Stars: ✭ 465 (+761.11%)
Mutual labels:  framework, foundation
Criollo
A powerful Cocoa web framework and HTTP server for macOS, iOS and tvOS.
Stars: ✭ 229 (+324.07%)
Mutual labels:  framework, cocoa
Rearrange
Collection of utilities for interacting with NSRange and NSTextRange
Stars: ✭ 28 (-48.15%)
Mutual labels:  foundation, cocoa
Fruity
Rusty bindings for Apple libraries
Stars: ✭ 72 (+33.33%)
Mutual labels:  cocoa, foundation
Githubupdates
Cocoa framework to install application updates from GitHub releases.
Stars: ✭ 393 (+627.78%)
Mutual labels:  framework, cocoa
Material Foundation
Material Design version of Foudation for Sites by Zurb
Stars: ✭ 361 (+568.52%)
Mutual labels:  framework, foundation
Stprivilegedtask
An NSTask-like wrapper around the macOS Security Framework's AEWP function to run shell commands with root privileges in Objective-C / Cocoa.
Stars: ✭ 335 (+520.37%)
Mutual labels:  wrapper, cocoa
Hzdtf.foundation.framework
基础框架系统,支持.NET和.NET Core平台,语言:C#,DB支持MySql和SqlServer,主要功能有抽象持久化、服务层,将业务基本的增删改查抽离复用;提供代码生成器从DB生成实体、持久化、服务以及MVC控制器,每层依赖接口,并需要在客户端将对应实现层用Autofac程序集依赖注入,用AOP提供日志跟踪、事务、模型验证等。对Autofac、Redis、RabbitMQ封装扩展;DB访问提供自动主从访问,Redis客户端分区。特别适合管理系统。
Stars: ✭ 22 (-59.26%)
Mutual labels:  framework, foundation
Orsserialport
Serial port library for Objective-C and Swift macOS apps
Stars: ✭ 609 (+1027.78%)
Mutual labels:  framework, cocoa
Objc Uti
Objective-C wrapper for Uniform Type Identifiers (UTIs)
Stars: ✭ 7 (-87.04%)
Mutual labels:  wrapper, cocoa
Betaexpiration
Beta period expiration code and window decoration for macOS app development
Stars: ✭ 51 (-5.56%)
Mutual labels:  framework
Brick
A declarative Unix terminal UI programming library written in Haskell
Stars: ✭ 1,070 (+1881.48%)
Mutual labels:  framework
Rest Control
Framework for testing and validation REST services
Stars: ✭ 51 (-5.56%)
Mutual labels:  framework
Lemon
🍋 Minimal and responsive CSS framework for fast building websites.
Stars: ✭ 51 (-5.56%)
Mutual labels:  framework
Framework
IONDV. Framework is a high level framework for enterprise web applications development.
Stars: ✭ 54 (+0%)
Mutual labels:  framework
Framework
Assely is a PHP framework which brings a little joy to the WordPress development. Develop structured, easily scalable and complex WordPress websites and web applications with true pleasure.
Stars: ✭ 53 (-1.85%)
Mutual labels:  framework

OBJCXX

Build Status Build-AppVeyor Coverage Status Issues Status License Contact
Donate-Patreon Donate-Gratipay Donate-Paypal

About

OBJCXX is a C++ wrapper library for the Objective-C language and the Apple's Foundation framework.

It allows you to use the complete Foundation framework using C++ on macOS and Windows without the need of an Objective-C compiler.

Technical Details

This library uses the Objective-C runtime to interact with the Foundation framework's classes.
As the Objective-C runtime is a C API, an Objective-C compiler is not required.

All Foundation classes are wrapped by C++ counterparts, which can be used with automatic allocation.
Memory is automatically managed. Objective-C instances are retained by their C++ counterparts, and released when necessary.

Example

Here's an hello world example using OBJCXX:

#include <OBJCXX.h>

int main( void )
{
    NS::Log( "%@", NS::String( "hello, world" ) );
    
    return 0;
}

Here's a more complex example:

#include <OBJCXX.h>

int main( void )
{
    /* Equivalent to @autoreleasepool */
    NS::AutoreleasePool ap;
    
    /* NSMutableArray */
    {
        NS::MutableArray o;
        
        std::cout << o << std::endl;
        
        o.addObject( NS::String( "hello, world" ) );
        o.addObject( NS::String( "hello, universe" ) );
        
        std::cout << o << std::endl;
    }
    
    /* NSMutableDictionary */
    {
        NS::MutableDictionary o;
        
        std::cout << o << std::endl;
        
        o.setObjectForKey( NS::String( "hello, world" ),    NS::String( "key-1" ) );
        o.setObjectForKey( NS::String( "hello, universe" ), NS::String( "key-2" ) );
        
        std::cout << o << std::endl;
    }
    
    /* NSFileManager */
    {
        NS::Error e;
        
        std::cout << NS::FileManager::defaultManager().attributesOfItemAtPath( "/~/Desktop/", e ) << std::endl;
    }
    
    return 0;
}

Creating Objective-C classes from C++

OBJCXX also allows you to dynamically create Objective-C classes at runtime.
While this is of course possible using the Objective-C runtime, OBJCXX makes this process much more simpler.

As an example:

#include <OBJCXX.h>

int main( void )
{
    /* Class Foo inheriting from NSObject */
    OBJCXX::ClassBuilder cls( "Foo", "NSObject" );
    
    /* Adds properties - Getters and setters are automatically generated */
    cls.addProperty( "title",     OBJCXX::ClassBuilder::TypeObject );
    cls.addProperty( "isEnabled", OBJCXX::ClassBuilder::TypeBool );
    cls.addProperty( "index",     OBJCXX::ClassBuilder::TypeSignedInt );
    
    /* Registers the class so it can be used */
    cls.registerClass();
    
    return 0;
}

The above example creates and registers a fully working Objective-C class similar to:

@interface Foo: NSObject

@property( nonatomic, readwrite, strong ) id   title;
@property( nonatomic, readwrite, assign ) BOOL isEnabled;
@property( nonatomic, readwrite, assign ) int  index;

@end

Adding custom methods

The example above only adds properties to the class, but custom methods can be added as well, and bound to C++ methods.

Imagine the following C++/Objective-C wrapper class, inheriting directly from NS::Object:

class Foo: public NS::Object
{
    public:
        
        OBJCXX_USING_BASE( Bar, Object )
        
        Foo( void ): Object( "Foo" )
        {}
        
        NS::String test( int x )
        {
            return std::to_string( x );
        }
};

The Objective-C class can be created the following way:

{
    OBJCXX::ClassBuilder cls( "Foo", "NSObject" );
    
    cls.instanceMethod< Foo, NS::String, int >( "test", &Foo::test, "" ).add< id, int >();
    cls.registerClass();
}

The template parameters of instanceMethod are the expected C++ types, while the template parameters of add are the expected Objective-C type.
This is necessary in order to convert the objects to/from C++ and Objective-C.

If the types are the same, the template parameters of add can be omitted, as they will be deduced automatically.

The example above will effectively add a instance method to the Foo class, which will be callable either from Objective-C or from C++, meaning the following:

objc_msgSend( Foo(), "test", 42 );

will effectively ends up calling the C++ method implementation.

License

OBJCXX is released under the terms of the MIT license.

Repository Infos

Owner:			Jean-David Gadina - XS-Labs
Web:			www.xs-labs.com
Blog:			www.noxeos.com
Twitter:		@macmade
GitHub:			github.com/macmade
LinkedIn:		ch.linkedin.com/in/macmade/
StackOverflow:	stackoverflow.com/users/182676/macmade
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].