]]>https://xcodeblog.com/2017/10/26/pring-firestore-model-framework.xcode/feed0MMWormhole – Message passing between iOS apps and extensions.https://xcodeblog.com/2017/10/24/mmwormhole-message-passing-ios-apps-extensions.xcode
https://xcodeblog.com/2017/10/24/mmwormhole-message-passing-ios-apps-extensions.xcode#respondTue, 24 Oct 2017 15:28:10 +0000https://awesomeswift.com/?p=842MMWormhole creates a bridge between an iOS or OS X extension and its containing application. The wormhole is meant to be used to pass data or commands back and forth between the two locations. Messages are archived to files which […]

]]>MMWormhole creates a bridge between an iOS or OS X extension and its containing application. The wormhole is meant to be used to pass data or commands back and forth between the two locations. Messages are archived to files which are written to the application’s shared App Group. The effect closely resembles interprocess communication between the app and the extension, though true interprocess communication does not exist between extensions and containing apps.

The wormhole also supports CFNotificationCenter Darwin Notifications in an effort to support realtime change notifications. When a message is passed to the wormhole, interested parties can listen and be notified of these changes on either side of the wormhole. The effect is nearly instant updates on either side when a message is sent through the wormhole.

Getting Started

Begin using MMWormhole to pass messages between your App and Extension

Note

The MMWormhole Example app will only work with your shared App Group identifiers and Entitlements and is meant purely for reference

##Installing MMWormhole
You can install Wormhole in your project by using CocoaPods:

pod 'MMWormhole', '~> 2.0.0'

MMWormhole also supports Carthage.

Overview

MMWormhole is designed to make it easy to share very basic information and commands between an extension and it’s containing application. The wormhole should remain stable whether the containing app is running or not, but notifications will only be triggered in the containing app if the app is awake in the background. This makes MMWormhole ideal for cases where the containing app is already running via some form of background modes.

A good way to think of the wormhole is a collection of shared mailboxes. An identifier is essentially a unique mailbox you can send messages to. You know where a message will be delivered to because of the identifier you associate with it, but not necessarily when the message will be picked up by the recipient. If the app or extension are in the background, they may not receive the message immediately. By convention, sending messages should be done from one side to another, not necessarily from yourself to yourself. It’s also a good practice to check the contents of your mailbox when your app or extension wakes up, in case any messages have been left there while you were away.

MMWormhole uses NSKeyedArchiver as a serialization medium, so any object that is NSCoding compliant can work as a message. For many apps, sharing simple strings, numbers, or JSON objects is sufficient to drive the UI of a Widget or Apple Watch app. Messages can be sent and persisted easily as archive files and read later when the app or extension is woken up later.

Using MMWormhole is extremely straightforward. The only real catch is that your app and it’s extensions must support shared app groups. The group will be used for writing the archive files that represent each message. While larger files and structures, including a whole Core Data database, can be shared using App Groups, MMWormhole is designed to use it’s own directory simply to pass messages. Because of that, a best practice is to initialize MMWormhole with a directory name that it will use within your app’s shared App Group.

Initialization

Initialize MMWormhole with your App Group identifier and an optional directory name

Designing Your Communication Scheme

You can think of message passing between apps and extensions sort of like a web service. The web service has endpoints that you can read and write. The message identifiers for your MMWormhole messages can be thought of in much the same way. A great practice is to design very clear message identifiers so that you immediately know when reading your code who sent the message and why, and what the possible contents of the message might be. Just like you would design a web service with clear semantics, you should do the same with your wormhole messaging scheme.

Communication with WatchConnectivity

The design of your communication scheme is even more important when you need to support watchOS 2. MMWormhole supports the WatchConnectivity framework provided by Apple as an easy way to get up and running quickly with a basic implementation of WatchConnectivity. This support is not intended to replace WatchConnectivity entirely, and it’s important to carefully consider your watch app’s communication system to see where MMWormhole will fit best.

Here are two things you need to know if you want to use WatchConnectivity support in your app:

MMWormholeSession is a singleton subclass of MMWormhole that supports listening for WatchConnectivity messages. It should be used as the listener for all MMWormhole messages you expect to receive from the WatchConnectivity framework. Be sure to activate the session once your listeners are set so that you can begin receiving message notifications.

Use the MMWormholeSessionTransiting types described below when creating your wormholes, but be careful not to send too many messages at once. You can easily overload the pipeline by sending too many messages at once.

Message Transiting Options

The mechanism by which data flows through MMWormhole is defined by the MMWormholeTransiting protocol. The default implementation of the protocol is called MMWormholeFileTransiting, which reads and writes messages as archived data files in the app groups shared container. Users of MMWormhole can implement their own version of this protocol to change the message passing behavior.

There are three new implementations of the MMWormholeTransiting protocol that support the WCSession application context, message, and file transfer systems. You may only use one form of transiting with a wormhole at a time, so you need to consider which type of messaging system best fits a given part of your application.

Most apps will find the application context system to be a good balance between real time messaging and simple persistence, so we recommend MMWormholeSessionContextTransiting as the best place to start. Check out the documentation and header comments for descriptions about the other messaging types.

You can get started quickly with a wormhole using one of the built in transiting types by calling the optional initializer to set up an instance with the right transiting type for your use case.

Overview

Image layer mask is a fundamental technique in image manipulations. It allows you to selectively modify the opacity (transparency) of the layer they belong to. This flexibility to define the opacity of different areas of a layer is the basis for more interesting image manipulation techniques such as selective coloring and luminosity masking.

The current version of TinyCrayon SDK provides the following three tools:

Quick Select: Smart and easy to use, users just need to select part of the object and the edge detection algorithm will find the boundary.

Hair Brush: Smooth and natual looking, paint on the hair/fur of an object and the algorithm will select the hair/fur for you in high quality.

Regular Brush: A regular brush tool with the capability to adjust its size, hardness and opacity.

Features

Free: TinyCrayon SDK is provided under MIT license, you can use it in your commercial applications for free!

iPad support: TinyCrayon SDK uses auto layout for its views and adapts to each screen size – iPhone or iPad.

Highly customizable: Style the UI, view modes and localized languages as you wish.

Swift: Keeping up with time, we chose Swift as the main development language of the TinyCrayon SDK, leading to leaner easier code.

Mappable Protocol

mutating func mapping(map: Map)

This function is where all mapping definitions should go. When parsing JSON, this function is executed after successful object creation. When generating JSON, it is the only function that is called on the object.

init?(map: Map)

This failable initializer is used by ObjectMapper for object creation. It can be used by developers to validate JSON prior to object serialization. Returning nil within the function will prevent the mapping from occuring. You can inspect the JSON stored within the Map object to do your validation:

StaticMappable Protocol

StaticMappable is an alternative to Mappable. It provides developers with a static function that is used by ObjectMapper for object initialization instead of init?(map: Map).

Note: StaticMappable, like Mappable, is a sub protocol of BaseMappable which is where the mapping(map: Map) function is defined.

static func objectForMapping(map: Map) -> BaseMappable?

ObjectMapper uses this function to get objects to use for mapping. Developers should return an instance of an object that conforms to BaseMappable in this function. This function can also be used to:

validate JSON prior to object serialization

provide an existing cached object to be used for mapping

return an object of another type (which also conforms to BaseMappable) to be used for mapping. For instance, you may inspect the JSON to infer the type of object that should be used for mapping (see examples in ClassClusterTests.swift)

If you need to implemented ObjectMapper in an extension, you will need to select this protocol instead of Mappable.

ImmutableMappable Protocol

ImmutableMappable provides the ability to map immutable properties. This is how ImmutableMappable differs from Mappable:

mutating func mapping(map: Map)

This method is where the reverse transform is performed (Model to JSON). Since immutable properties can not be mapped with the <- operator, developers have to define the reverse transform using the >>> operator.

Custom Transforms

ObjectMapper also supports custom transforms that convert values during the mapping process. To use a transform, simply create a tuple with map["field_name"] and the transform of your choice on the right side of the <- operator:

birthday <- (map["birthday"], DateTransform())

The above transform will convert the JSON Int value to an Date when reading JSON and will convert the Date to an Int when converting objects to JSON.

You can easily create your own custom transforms by adopting and implementing the methods in the TransformTypeprotocol:

TransformOf

In a lot of situations you can use the built-in transform class TransformOf to quickly perform a desired transformation. TransformOf is initialized with two types and two closures. The types define what the transform is converting to and from and the closures perform the actual transformation.

For example, if you want to transform a JSON String value to an Int you could use TransformOf as follows:

ObjectMapper + Alamofire

If you are using Alamofire for networking and you want to convert your responses to Swift objects, you can use AlamofireObjectMapper. It is a simple Alamofire extension that uses ObjectMapper to automatically map JSON response data to Swift objects.

ObjectMapper + Realm

ObjectMapper and Realm can be used together. Simply follow the class structure below and you will be able to use ObjectMapper to generate your Realm models:

If you want to serialize associated RealmObjects, you can use ObjectMapper+Realm. It is a simple Realm extension that serializes arbitrary JSON into Realm’s List class.

To serialize Swift String, Int, Double and Bool arrays you can use ObjectMapperAdditions/Realm. It’ll wrap Swift types into RealmValues that can be stored in Realm’s List class.

Note: Generating a JSON string of a Realm Object using ObjectMappers’ toJSON function only works within a Realm write transaction. This is caused because ObjectMapper uses the inout flag in its mapping functions (<-) which are used both for serializing and deserializing. Realm detects the flag and forces the toJSON function to be called within a write block even though the objects are not being modified.

Installation

Build for iOS/OSX

Build for Android

Build for Windows

Build for Linux

Basic IMAP Usage

Using MailCore 2 is just a little more complex conceptually than the original MailCore. All fetch requests in MailCore 2 are made asynchronously through a queue. What does this mean? Well, let’s take a look at a simple example:

In this sample, we retrieved and printed a list of email headers from an IMAP server. In order to execute the fetch, we request an asynchronous operation object from the MCOIMAPSession instance with our parameters (more on this later). This operation object is able to initiate a connection to Gmail when we call the start method. Now here’s where things get a little tricky. We call the start function with an Objective-C block, which is executed on the main thread when the fetch operation completes. The actual fetching from IMAP is done on a background thread, leaving your UI and other processing free to use the main thread.

]]>https://xcodeblog.com/2017/10/22/mailcore-2-simple-asynchronous-api-work-e-mail-protocols-imap-pop-smtp.xcode/feed0TweenKit – Animation library for iOS in Swifthttps://xcodeblog.com/2017/10/22/tweenkit-animation-library-ios-swift.xcode
https://xcodeblog.com/2017/10/22/tweenkit-animation-library-ios-swift.xcode#respondSun, 22 Oct 2017 05:17:35 +0000https://awesomeswift.com/?p=829TweenKit is a powerful animation library that allows you to animate (or ‘tween’) anything. TweenKit’s animations are also scrubbable, perfect for building awesome onboarding experiences! Download the example project to see how these animations were created TweenKit’s animations are: Reversible […]

]]>TweenKit is a powerful animation library that allows you to animate (or ‘tween’) anything. TweenKit’s animations are also scrubbable, perfect for building awesome onboarding experiences!

Download the example project to see how these animations were created

TweenKit’s animations are:

Reversible

Repeatable

Groupable

Sequenceable

Scrubbable

Quick and easy to use!

Example

The example project contains a collection of examples of how to use TweenKit. Run Example.xcodeproj

Installation

TweenKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "TweenKit"

Importing TweenKit

Add import TweenKit to the top of the files you want to use TweenKit from

Creating an ActionScheduler

Create an instance of ActionScheduler to run your animations. You should retain the scheduler, so it’s best made as a property on your View Controller.

let scheduler = ActionScheduler()

Actions

TweenKit’s animations are composed of ‘Actions’. These are small animation units that can be chained or grouped to build complex animations. Once you have created an action, you can tell the scheduler to run it.

scheduler.run(action: myAction)

Animating a view’s frame

Anything that conforms to the ‘Tweenable’ protocol, can be animated.

CGRect, CGFloat, Double, Float, UIColor, and other common objects already adopt the ‘Tweenable’ out of the box.