Skip to content

Commit

Permalink
Merge branch 'release/1.1.5'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
KWANG HYOUN KIM committed Jan 14, 2019
2 parents def286a + 6e4c1e2 commit 0bf7f1e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 23 deletions.
13 changes: 2 additions & 11 deletions APNSUtil.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,14 @@

Pod::Spec.new do |s|
s.name = 'APNSUtil'
s.version = '1.1.4'
s.version = '1.1.5'
s.summary = 'APNSUtil is makes code simple using apple push notification service.'
s.description = 'APNSUtil is makes code simple using apple push notification service.'
s.homepage = 'https://github.com/pisces/APNSUtil'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'pisces' => '[email protected]' }
s.source = { :git => 'https://github.com/pisces/APNSUtil.git', :tag => s.version.to_s }
s.ios.deployment_target = '9.0'
s.source_files = 'APNSUtil/Classes/**/*'
s.dependency 'ObjectMapper', '~> 3.1'
s.default_subspec = 'Core'

s.subspec 'Core' do |core|
core.source_files = 'APNSUtil/Classes/**/*'
end

s.subspec 'AppExtension' do |ext|
ext.source_files = 'APNSUtil/Classes/**/*'
ext.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-DAPP_EXTENSIONS' }
end
end
60 changes: 52 additions & 8 deletions APNSUtil/Classes/NSObject+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,66 @@
import Foundation

extension NSObject {

// MARK: - Properties

public var mirrorChildList: [Mirror.Child] {
return Mirror(reflecting: self).children.filter { $0.label != nil }
}

// MARK: - Public methods

public func encodeProperties(with corder: NSCoder, ignoreKeys: [String]? = nil) {
mirrorChildList.forEach {
let mirror = Mirror(reflecting: self)
var current = mirror.superclassMirror

while current != nil {
encodeChildren(filteredChildren(current), corder: corder, ignoreKeys: ignoreKeys)
current = current?.superclassMirror
}

encodeChildren(filteredChildren(mirror), corder: corder, ignoreKeys: ignoreKeys)
}
public func decodeProperties(with corder: NSCoder, ignoreKeys: [String]? = nil) {
let mirror = Mirror(reflecting: self)
var current = mirror.superclassMirror

while current != nil {
decodeChildren(filteredChildren(current), corder: corder, ignoreKeys: ignoreKeys)
current = current?.superclassMirror
}

decodeChildren(filteredChildren(mirror), corder: corder, ignoreKeys: ignoreKeys)
}
public func dictionary(ignoreKeys: [String]? = nil) -> [String: Any] {
let mirror = Mirror(reflecting: self)
var current = mirror.superclassMirror
var dict = [String: Any]()

while current != nil {
setValue(with: filteredChildren(current), dict: &dict, ignoreKeys: ignoreKeys)
current = current?.superclassMirror
}

setValue(with: filteredChildren(mirror), dict: &dict, ignoreKeys: ignoreKeys)

return dict
}

// MARK: - Private methods

private func encodeChildren(_ children: [Mirror.Child]?, corder: NSCoder, ignoreKeys: [String]? = nil) {
children?.forEach {
if let ignoreKeys = ignoreKeys, ignoreKeys.contains($0.label!) {
return
}

if !($0.value is NSNull) {
corder.encode($0.value, forKey: $0.label!)
}
}
}
public func decodeProperties(with corder: NSCoder, ignoreKeys: [String]? = nil) {
mirrorChildList.forEach {
private func decodeChildren(_ children: [Mirror.Child]?, corder: NSCoder, ignoreKeys: [String]? = nil) {
children?.forEach {
if let ignoreKeys = ignoreKeys, ignoreKeys.contains($0.label!) {
return
}
Expand All @@ -34,14 +77,15 @@ extension NSObject {
}
}
}
public func dictionary(ignoreKeys: [String]? = nil) -> [String: Any] {
var dict = [String: Any]()
mirrorChildList.forEach {
private func filteredChildren(_ mirror: Mirror?) -> [Mirror.Child] {
return mirror?.children.filter { $0.label != nil } ?? []
}
private func setValue(with children: [Mirror.Child]?, dict: inout [String: Any], ignoreKeys: [String]? = nil) {
children?.forEach {
if let ignoreKeys = ignoreKeys, ignoreKeys.contains($0.label!) {
return
}
dict[$0.label!] = value(forKey: $0.label!)
}
return dict
}
}
22 changes: 22 additions & 0 deletions APNSUtilAppExtension.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Be sure to run `pod lib lint APNSUtil.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 = 'APNSUtilAppExtension'
s.version = '1.1.5'
s.summary = 'APNSUtil is makes code simple using apple push notification service.'
s.description = 'APNSUtil is makes code simple using apple push notification service.'
s.homepage = 'https://github.com/pisces/APNSUtil'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'pisces' => '[email protected]' }
s.source = { :git => 'https://github.com/pisces/APNSUtil.git', :tag => s.version.to_s }
s.ios.deployment_target = '9.0'
s.source_files = 'APNSUtil/Classes/**/*'
s.dependency 'ObjectMapper', '~> 3.1'
s.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-DAPP_EXTENSIONS' }
end
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct APNSPayload: Mappable {
$ gem install cocoapods
```

> CocoaPods 1.1.2+ is required to build APNSUtil 1.0.0+.
> CocoaPods 1.0.0+ is required to build APNSUtil 1.1.5+.
To integrate APNSUtil into your Xcode project using CocoaPods, specify it in your `Podfile`:

Expand All @@ -141,12 +141,12 @@ platform :ios, '9.0'

# Default
target '<Your Target Name>' do
pod 'APNSUtil', '~> 1.1.4'
pod 'APNSUtil', '~> 1.1.5'
end

# for AppExtension
target '<Your Target Name>' do
pod 'APNSUtil/AppExtension', '~> 1.1.4'
pod 'APNSUtil/AppExtension', '~> 1.1.5'
end
```

Expand All @@ -170,7 +170,7 @@ $ brew install carthage
To integrate Alamofire into your Xcode project using Carthage, specify it in your `Cartfile`:

```ogdl
github "pisces/APNSUtil" ~> 1.1.4
github "pisces/APNSUtil" ~> 1.1.5
```

Run `carthage update` to build the framework and drag the built `APNSUtil.framework` into your Xcode project.
Expand Down

0 comments on commit 0bf7f1e

Please sign in to comment.