A framework for sharing code between iOS and OS X

Related tags

Bridging MAIKit
Overview

MAIKit

MAIKit (Mac and iOS Kit) is a framework for sharing code between OS X and iOS.

UIKit contains many classes which have counterparts in Appkit. These classes contain many, but not all of the same methods and properties. For example, UIColor and NSColor are nearly identical, but NSColor contains constructors for creating colors from calibrated and device values, which UIColor does not, and UIColor has a CIColor property, which NSColor does not.

Many projects use @compatibility_alias to alias UIColor to NSColor in order to share code between iOS and OS X apps. However, this approach has some drawbacks. One such drawback is that it is still possible to write and compile code that works on one platform but not the other. For example, the following code would compile for iOS, but not OS X.

let ciColor = NSColor.blackColor().CIColor

Of course, this error would be easily caught the next time the code was compiled for OS X, but constantly compiling for both platforms slows down development. Furthermore, it takes longer to correct problems than to prevent them, and when working on a team, if the build error is not caught before it is committed, could prevent other team members from completing their work until it is fixed. The @compatibility_alias method also exposes platform-specific methods and properties to autocomplete, leaving to the developer the responsibility of remembering which APIs are available on both platforms, and which APIs are not.

MAIKit aims to prevent these problems, speeding up cross-platform development. It does so by defining protocols which contain the intersection of methods and properties of UIKit and AppKit classes. It also defines classes which implement these protocols, and can be used in both iOS and OS X code. These classes inherit from their UIKit and Appkit counterparts, and can be safely subclassed.

Continuing the NSColor example, MAIKit defines a class named MAIColor, and a protocol named MAIColorProtocol. The same pattern applies to all UIKit and AppKit classes.

When declaring variables, you will need to declare them as MAIKit-defined protocols in Swift, or as Objective-C objects conforming to those protocols. You cannot instantiate protocols, however, so you will need to initialize them using MAIKit-defined classes.

let maiColor : MAIColorProtocol = MAIColor.blackColor()
let cgColor = maiColor.CGColor
id<MAIColorProtocol> maiColor = [MAIColor blackColor];
CGColorRef cgColor = [maiColor CGColor];

Examples

The MAIKit/Examples folder contains an example project which demonstrates how to subclass views and viewcontrollers and how to handle events in mostly cross-platform code.

If you wish to contribute additional examples, please open a pull request. I will be happy to include them.

Versioning

MAIKit attempts to remain compatible with semantic versioning by only introducing API-incompatible changes in major versions. Because iOS SDK versions are usually tied to Xcode versions, MAIKit's major version changes whenever Xcode's major or minor version changes. MAIKit's minor version corresponds to Xcode's patch version, and MAIKit's patch version is independant of Xcode's version.

For example, Xcode 7.0.0, which contains iOS SDK 9.0 and OS X SDK 10.10, corresponds to MAIKit versions 70.0.x. If MAIKit releases 3 versions total during Xcode 7.0.0's life, then MAIKit will be at 70.0.2. If Xcode 7.0.1 is then released with minor API changes, MAIKit will incorporate those changes in a version 70.1.0. When Xcode 7.1.0 is released, MAIKit's version will increase to 71.0.0.

During Xcode betas, MAIKit may introduce API-incompatible changes without increasing the major version number, because Xcode builds with the same version number may introduce API-breaking changes.

Installation

Carthage

Start by adding the following line to your Cartfile.

github "MichaelBuckley/MAIKit" ~> 70.0.0

Full instructions on installing dependencies with Carthage can be found in Carthage's README.

CocoaPods

Add the following line to your Podfile.

pod 'MAIKit', '~> 70.0.0'

Then, run pod update.

License

MAIKit is released under the MIT license.

You might also like...
Syntax sugar of OpenTok iOS SDK with Audio/Video communication including screen sharing
Syntax sugar of OpenTok iOS SDK with Audio/Video communication including screen sharing

Accelerator Core iOS The Accelerator Core is a solution to integrate audio/video communication to any iOS applications via OpenTok platform. Accelerat

Easy Proximity-based Bluetooth LE Sharing for iOS

Description Easy Proximity-based Sharing for iOS Perfect for any iOS app that needs to quickly share items with nearby friends, such as groups, photo

iOS ReplayKit Screen Share Broadcast Extension Frame Sharing

An iOS app that demonstrates how we can share CMSampleBuffer frames from SampleHandler of Broadcast Extension to the host app and how to pass callbacks to and fro from host app to SampleHandler and vice versa.

Ported Shamirs Secret Sharing Into A Swift Package

Shamirs-Secret-Sharing-Swift Ported Shamirs Secret Sharing Into A Swift Package Based on Adi Shamir's Secret Sharing (https://en.wikipedia.org/wiki/Sh

PhoneGap / Cordova Social Sharing plugin

PhoneGap / Cordova Social Sharing plugin Every now and then kind folks ask me how they can give me all their money. So if you want to contribute to my

SocialLib handles sharing message to multiple social media.

SocialLib ###What is SocialLib? SocialLib is a library that aims to share information to different social media site without getting your code messy w

A way to represent what you’re sharing.
A way to represent what you’re sharing.

About This project provides a preview of items being shared via UIActivityViewController. Example: // standard activity view controller let vc = UIAct

WebDomHandling - A Swift Package for handling JavaScript code between WebKit and Swift implemented by WebKit

WebDomHandling A Swift Package for handling JavaScript code between WebKit and S

A μlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and emoji.

CountryKit CountryKit A μlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and e

MultiPeer-Progress-iOS - Swift project to demo the use of the MultiPeer framework to send files between iOS devices and show the progress
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

CloudCore is a framework that manages syncing between iCloud (CloudKit) and Core Data written on native Swift.
CloudCore is a framework that manages syncing between iCloud (CloudKit) and Core Data written on native Swift.

CloudCore CloudCore is a framework that manages syncing between iCloud (CloudKit) and Core Data written on native Swift. Features Leveraging NSPersist

iOS framework for impressive transition animations between views.

CoreTransition iOS framework for impressive transition animations between views. Built using Swift, and supports a lot of animations to navigate to a

📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

A framework for streaming audio between Apple devices using AirPlay.

Airstream An iOS / macOS framework for streaming audio between Apple devices using AirPlay. You can use Airstream to start an AirPlay server in your i

Bonjour networking for discovery and connection between iOS, macOS and tvOS devices.
Bonjour networking for discovery and connection between iOS, macOS and tvOS devices.

Merhaba Bonjour networking for discovery and connection between iOS, macOS and tvOS devices. Features Creating Service Start & Stop Service Stop Brows

Classes-and-structures-in-swift - This source files show what is the difference between class and structure

This source files show what is the difference between class and structure You ca

SwiftUI view enabling navigation between pages of content, imitating the behaviour of UIPageViewController for iOS and watchOS
SwiftUI view enabling navigation between pages of content, imitating the behaviour of UIPageViewController for iOS and watchOS

PageView SwiftUI view enabling page-based navigation, imitating the behaviour of UIPageViewController in iOS. Why SwiftUI doesn't have any kind of pag

Comments
  • @class and @protocol declarations take up too much room

    @class and @protocol declarations take up too much room

    The @class and @protocol declarations at the top of every header file take up a ton of room and make it difficult to read the actual interfaces.

    I'd suggest doing: "@class MAIDataAsset, MAILayoutXAxisAnchor, MAILayoutYAxisAnchor, " etc and getting it all taken care of on one line rather than >100 lines being protocol and class declarations.

    Additionally, I don't believe it's necessary to to #import TargetConditionals.h if you are importing UIKit and AppKit?

    opened by AriX 2
Owner
Michael Buckley
Michael Buckley
JSPatch bridge Objective-C and Javascript using the Objective-C runtime. You can call any Objective-C class and method in JavaScript by just including a small engine. JSPatch is generally used to hotfix iOS App.

JSPatch 中文介绍 | 文档 | JSPatch平台 请大家不要自行接入 JSPatch,统一接入 JSPatch 平台,让热修复在一个安全和可控的环境下使用。原因详见 这里 JSPatch bridges Objective-C and JavaScript using the Object

bang 11.4k Jan 1, 2023
Photo-Sharing-App - Photo Sharing App With Swift

Photo Sharing App You can register and log in to this application and share your

Yağız Savran 2 Jun 14, 2022
Easier sharing of structured data between iOS applications and share extensions

XExtensionItem XExtensionItem is a tiny library allowing for easier sharing of structured data between iOS applications and share extensions. It is ta

Tumblr 86 Nov 23, 2022
Sample app to demonstrate data sharing between a WatchKit app and its main app using Realm

#Done! A sample app demonstrating how to share data between an app an its Watch extension using Realm. You can read more about it here. ##Screenshot #

Fancy Pixel 147 Dec 8, 2022
Sample app to demonstrate data sharing between a WatchKit app and its main app using Realm

#Done! A sample app demonstrating how to share data between an app an its Watch extension using Realm. You can read more about it here. ##Screenshot #

Fancy Pixel 147 Dec 8, 2022
Sharing SQL queries between Server and Mobile databases

Sharing SQL queries between Server and Mobile databases Overview As we all know, code is expensive to maintain, and the more complex the code, the mor

Aaron LaBeau 4 May 24, 2022
A tool for Swift code modification intermediating between code generation and formatting.

swift-mod A tool for Swift code modification intermediating between code generation and formatting. Overview swift-mod is a tool for Swift code modifi

Ryo Aoyama 95 Nov 3, 2022
Jogendra 113 Nov 28, 2022
iOS On-Device Game Cheat Creation/Sharing Platform and Software

CheatManager CheatManager is a mobile platform, used for installation/distribution/creation of mobile game cheats/hacks. This platform is completely d

Project Manticore 49 Jan 2, 2023
TripUp is an open source, photo storage and sharing app made for privacy conscious users.

TripUp is an open source, photo storage and sharing app made for privacy conscious users.

TripUp 19 Aug 26, 2022