Skip to content

Commit

Permalink
Prepare the project to push the podspec (#3)
Browse files Browse the repository at this point in the history
* minor changes in the podspec

* cocoapods statuses are added to the readme; the changelog is updated

* public interface is documented

* changelog is updated
  • Loading branch information
Artem Stepanenko authored Jan 8, 2017
1 parent ba09b0e commit 930601d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 31 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Sourcery CHANGELOG
# Dekoter

---

## 0.1.0

### Features

* Basic functionality: a `Koting` protocol and a `Koter`.
* API is polished
* Unit tests are added
* Readme is done
* Basic Travis setup is done
* Basic Travis setup is done
* Podspec is prepared to be pushed
* Cocoapods' statuses are added to the readme
* Xcode documentation is added
33 changes: 4 additions & 29 deletions Dekoter.podspec
Original file line number Diff line number Diff line change
@@ -1,42 +1,17 @@
#
# Be sure to run `pod lib lint Dekoter.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = 'Dekoter'
s.version = '0.1.0'
s.summary = "`NSCoding`'s counterpart for Swift structs."

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!

s.summary = "NSCoding's counterpart for Swift structs."

s.description = <<-DESC
Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Fills a gap left by the missing NSCoding's support for Swift structs. If you've ever implemented NSCoding, Koting will be familiar to you as well.
DESC

s.homepage = 'https://github.com/artemstepanenko/Dekoter'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Artem Stepanenko' => '[email protected]' }
s.source = { :git => 'https://github.com/artemstepanenko/Dekoter.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'


s.ios.deployment_target = '9.0'

s.source_files = 'Dekoter/Classes/**/*'

# s.resource_bundles = {
# 'Dekoter' => ['Dekoter/Assets/*.png']
# }

# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
30 changes: 30 additions & 0 deletions Dekoter/Classes/Koter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import Foundation


/// Collects a content of an object to be converted to Data and back – from Data to the initial type.
public class Koter {

// MARK: - Property
Expand All @@ -33,10 +35,18 @@ public class Koter {

// MARK: - Koting / Dekoting

/// Decodes and returns an object that was previously encoded and associated with the string key.
///
/// - Parameter key: the string key
/// - Returns: the object that was previously encoded
public func dekotObject<T>(forKey key: AnyHashable) -> T? {
return objects[key] as? T
}

/// Decodes and returns an object which implements Koting that was previously encoded and associated with the string key.
///
/// - Parameter key: the string key
/// - Returns: the object which implements Koting that was previously encoded
public func dekotObject<T: Koting>(forKey key: AnyHashable) -> T? {
guard let data = objects[key] as? Data,
let codingObject = T.de_from(data: data) else {
Expand All @@ -46,13 +56,22 @@ public class Koter {
return codingObject
}

/// Decodes and returns an array of objects which implement Koting that was previously encoded and associated with the string key.
///
/// - Parameter key: the string key
/// - Returns: the array of objects which implement Koting that was previously encoded
public func dekotObject<T: Koting>(forKey key: AnyHashable) -> [T]? {
guard let datas = objects[key] as? [Data] else {
return nil
}
return datas.flatMap { T.de_from(data: $0) }
}

/// Encodes an object which implements Koting and associates it with the string key.
///
/// - Parameters:
/// - object: the object which implements Koting
/// - key: the string key
public func enkotObject<T: Koting>(_ object: T?, forKey key: AnyHashable) {
guard let object = object, let data = object.de_data else {
objects[key] = NSNull()
Expand All @@ -61,6 +80,11 @@ public class Koter {
objects[key] = data
}

/// Encodes an array of objects which implement Koting and associates it with the string key.
///
/// - Parameters:
/// - object: the array of objects which implement Koting
/// - key: the string key
public func enkotObject<T: Koting>(_ object: [T]?, forKey key: AnyHashable) {
guard let object = object else {
objects[key] = NSNull()
Expand All @@ -69,6 +93,12 @@ public class Koter {
objects[key] = object.flatMap { $0.de_data }
}


/// Encodes an object and associates it with the string key.
///
/// - Parameters:
/// - object: the object
/// - key: the string key
public func enkotObject<T>(_ object: T?, forKey key: AnyHashable) {
guard let object = object else {
objects[key] = NSNull()
Expand Down
10 changes: 10 additions & 0 deletions Dekoter/Classes/Koting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,33 @@

import Foundation


/// Declares four methods. Two of them are already implemented, they may be used to encode/decode objects of the type (struct or class) to/from a data. Remaining two methods must be implemented.
public protocol Koting {

var de_data: Data? { get }
static func de_from(data: Data) -> Self?

// MARK: - To Be Overriden

init?(koter: Koter)
func enkot(with koter: Koter)
}

public extension Koting {

/// Tries to encode an object to a data. (Returns nil, if the object contains a property of an unsupported type.)
var de_data: Data? {
let koter = Koter()
enkot(with: koter)
return NSKeyedArchiver.archivedData(withRootObject: koter.objects)
}


/// Tries to decode a data to an object.
///
/// - Parameter data: the data that an object of the given type was previously encoded to
/// - Returns: the object similar to the one that was previously encoded to the provided data. Returns nil, if the data was created differently.
static func de_from(data: Data) -> Self? {
guard let topObject = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data as NSData),
let objects = topObject as? [AnyHashable: Any] else {
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Dekoter

[![Build Status](https://travis-ci.org/artemstepanenko/Dekoter.svg?branch=master)](https://travis-ci.org/artemstepanenko/Dekoter)
[![Version](https://img.shields.io/cocoapods/v/Dekoter.svg?style=flat)](http://cocoapods.org/pods/Dekoter)
[![License](https://img.shields.io/cocoapods/l/Dekoter.svg?style=flat)](http://cocoapods.org/pods/Dekoter)
[![Platform](https://img.shields.io/cocoapods/p/Dekoter.svg?style=flat)](http://cocoapods.org/pods/Dekoter)

- [Why You Might Be Interested](#why-you-might-be-interested)
- [How Much Familiar It Feels](#how-much-familiar-it-feels)
Expand Down

0 comments on commit 930601d

Please sign in to comment.