Commit ccc51561 by Daniel Dahan

development: added DynamicFontType and JSON classes

parent 562141d5
......@@ -9,6 +9,9 @@
/* Begin PBXBuildFile section */
961F18E81CD93E3E008927C5 /* ErrorTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961F18E71CD93E3E008927C5 /* ErrorTextField.swift */; };
9628645A1D53FE3E00690B69 /* Material+UIWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962864591D53FE3E00690B69 /* Material+UIWindow.swift */; };
9628645F1D540AF300690B69 /* DynamicFontType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9628645E1D540AF300690B69 /* DynamicFontType.swift */; };
962864621D54111D00690B69 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962864611D54111D00690B69 /* JSON.swift */; };
962864631D54111D00690B69 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962864611D54111D00690B69 /* JSON.swift */; };
96334EF61C8B84660083986B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96334EF51C8B84660083986B /* Assets.xcassets */; };
963832421B88DFD80015F710 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* Material.framework */; };
9658F2171CD6FA4700B902C1 /* IconButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9658F2161CD6FA4700B902C1 /* IconButton.swift */; };
......@@ -196,6 +199,8 @@
/* Begin PBXFileReference section */
961F18E71CD93E3E008927C5 /* ErrorTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorTextField.swift; sourceTree = "<group>"; };
962864591D53FE3E00690B69 /* Material+UIWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIWindow.swift"; sourceTree = "<group>"; };
9628645E1D540AF300690B69 /* DynamicFontType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DynamicFontType.swift; sourceTree = "<group>"; };
962864611D54111D00690B69 /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = "<group>"; };
96334EF51C8B84660083986B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
963832361B88DFD80015F710 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Material.framework; sourceTree = BUILT_PRODUCTS_DIR; };
963832411B88DFD80015F710 /* Material.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Material.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -323,6 +328,14 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
962864601D5410FD00690B69 /* JSON */ = {
isa = PBXGroup;
children = (
962864611D54111D00690B69 /* JSON.swift */,
);
name = JSON;
sourceTree = "<group>";
};
962A92581D42839100DBAF8E /* Data */ = {
isa = PBXGroup;
children = (
......@@ -422,6 +435,7 @@
96BCB80A1CB410A100C806FE /* Extension */,
96BCB8071CB4101C00C806FE /* Font */,
96BCB8081CB4105E00C806FE /* Icon */,
962864601D5410FD00690B69 /* JSON */,
968C99431D36ECBB000074FF /* Label */,
96BCB80D1CB410FD00C806FE /* Layer */,
96BCB8041CB40F6C00C806FE /* Layout */,
......@@ -563,6 +577,7 @@
children = (
96BCB77B1CB40DC500C806FE /* Font.swift */,
96BCB7941CB40DC500C806FE /* RobotoFont.swift */,
9628645E1D540AF300690B69 /* DynamicFontType.swift */,
);
name = Font;
sourceTree = "<group>";
......@@ -976,6 +991,7 @@
96BCB7D81CB40DC500C806FE /* MenuController.swift in Sources */,
96BCB7D41CB40DC500C806FE /* TransitionAnimation.swift in Sources */,
967A48191D0F425A00B8CEB7 /* StatusBarController.swift in Sources */,
962864621D54111D00690B69 /* JSON.swift in Sources */,
96BCB7C21CB40DC500C806FE /* Device.swift in Sources */,
96BCB7A41CB40DC500C806FE /* CaptureSession.swift in Sources */,
96BCB7C51CB40DC500C806FE /* MaterialGravity.swift in Sources */,
......@@ -997,6 +1013,7 @@
96BCB7A71CB40DC500C806FE /* ControlView.swift in Sources */,
96BCB7DB1CB40DC500C806FE /* NavigationItem.swift in Sources */,
96BCB7E01CB40DC500C806FE /* NavigationDrawerController.swift in Sources */,
9628645F1D540AF300690B69 /* DynamicFontType.swift in Sources */,
96BCB7AD1CB40DC500C806FE /* Material+String.swift in Sources */,
96BCB7A51CB40DC500C806FE /* Capture.swift in Sources */,
96BCB7B91CB40DC500C806FE /* Button.swift in Sources */,
......@@ -1027,6 +1044,7 @@
buildActionMask = 2147483647;
files = (
9661222E1D3EC414008BB4CB /* Color.swift in Sources */,
962864631D54111D00690B69 /* JSON.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
@objc(DynamicFontTypeDelegate)
public protocol DynamicFontTypeDelegate {
/**
A delegation method that is executed when the dynamic type
is changed.
- Parameter dynamicFontType: A DynamicFontType.
*/
func dynamicFontType(dynamicFontType: DynamicFontType)
}
@objc(DynamicFontType)
public class DynamicFontType: NSObject {
/// A weak reference to a DynamicFontTypeDelegate.
public weak var delegate: DynamicFontTypeDelegate?
/// Initializer.
public override init() {
super.init()
prepare()
}
internal func handleContentSizeChange() {
delegate?.dynamicFontType(dynamicFontType: self)
}
/// Prepare the instance object.
private func prepare() {
prepareContentSizeObservation()
}
/// Prepares observation for content size changes.
private func prepareContentSizeObservation() {
NotificationCenter.default.addObserver(self, selector: #selector(handleContentSizeChange), name: NSNotification.Name.UIContentSizeCategoryDidChange, object: nil)
}
}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import Foundation
public class JSON: Equatable, CustomStringConvertible {
/**
:name: description
*/
public var description: String {
return JSON.stringify(object) ?? "{}"
}
/**
:name: object
*/
public private(set) var object: AnyObject
/**
:name: asArray
*/
public var asArray: [AnyObject]? {
return object as? [AnyObject]
}
/**
:name: asDictionary
*/
public var asDictionary: [String: AnyObject]? {
return object as? [String: AnyObject]
}
/**
:name: asString
*/
public var asString: String? {
return object as? String
}
/**
:name: asInt
*/
public var asInt: Int? {
return object as? Int
}
/**
:name: asDouble
*/
public var asDouble: Double? {
return object as? Double
}
/**
:name: asFloat
*/
public var asFloat: Float? {
return object as? Float
}
/**
:name: asBool
*/
public var asBool: Bool? {
return object as? Bool
}
/**
:name: asNSData
*/
public var asNSData: NSData? {
return JSON.serialize(object: object)
}
/**
:name: parse
*/
public class func parse(_ data: Data, options: JSONSerialization.ReadingOptions = .allowFragments) -> JSON? {
if let object = try? JSONSerialization.jsonObject(with: data, options: options) {
return JSON(object)
}
return nil
}
/**
:name: parse
*/
public class func parse(_ json: String) -> JSON? {
guard let data = json.data(using: String.Encoding.utf8) else {
return nil
}
return parse(data)
}
/**
:name: serialize
*/
public class func serialize(object: AnyObject) -> Data? {
return try? JSONSerialization.data(withJSONObject: object, options: [])
}
/**
:name: stringify
*/
public class func stringify(_ object: AnyObject) -> String? {
if let o = object as? JSON {
return stringify(o.object)
} else if let data = JSON.serialize(object: object) {
if let o = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as? String {
return o
}
}
return nil
}
/**
:name: init
*/
public required init(_ object: AnyObject) {
if let o = object as? JSON {
self.object = o.object
} else {
self.object = object
}
}
/**
:name: operator [0...count - 1]
*/
public subscript(index: Int) -> JSON? {
if let item = asArray {
return JSON(item[index])
}
return nil
}
/**
:name: operator [key 1...key n]
*/
public subscript(key: String) -> JSON? {
if let item = asDictionary {
if nil != item[key] {
return JSON(item[key]!)
}
}
return nil
}
}
public func ==(lhs: JSON, rhs: JSON) -> Bool {
return JSON.stringify(lhs.object)! == JSON.stringify(rhs.object)!
}
......@@ -42,18 +42,22 @@ public extension Array where Element: Equatable {
if e >= count {
e = count - 1
}
guard -1 < start else {
fatalError("Range out of bounds for \(start) - \(end), should be 0 - \(count).")
}
var diff = abs(e - start)
guard count > diff else {
return self
}
var ret = [Element]()
while -1 < diff {
ret.insert(self[start + diff], at: 0)
diff -= 1
}
return ret
}
}
......@@ -194,12 +194,12 @@ public class PhotoLibrary: NSObject {
prepare()
}
/// A method used to prepare the instance object.
/// Prepare the instance object.
private func prepare() {
prepareChangeObservers()
}
/// A method used to enable change observation.
/// Prepares the PHPhotoLibrary change observation.
private func prepareChangeObservers() {
PHPhotoLibrary.shared().register(self)
}
......
......@@ -66,7 +66,7 @@ public protocol TextDelegate {
}
@objc(Text)
public class Text : NSObject {
public class Text: NSObject {
/// The string pattern to match within the textStorage.
public var pattern: String = "(^|\\s)#[\\d\\w_\u{203C}\u{2049}\u{20E3}\u{2122}\u{2139}\u{2194}-\u{2199}\u{21A9}-\u{21AA}\u{231A}-\u{231B}\u{23E9}-\u{23EC}\u{23F0}\u{23F3}\u{24C2}\u{25AA}-\u{25AB}\u{25B6}\u{25C0}\u{25FB}-\u{25FE}\u{2600}-\u{2601}\u{260E}\u{2611}\u{2614}-\u{2615}\u{261D}\u{263A}\u{2648}-\u{2653}\u{2660}\u{2663}\u{2665}-\u{2666}\u{2668}\u{267B}\u{267F}\u{2693}\u{26A0}-\u{26A1}\u{26AA}-\u{26AB}\u{26BD}-\u{26BE}\u{26C4}-\u{26C5}\u{26CE}\u{26D4}\u{26EA}\u{26F2}-\u{26F3}\u{26F5}\u{26FA}\u{26FD}\u{2702}\u{2705}\u{2708}-\u{270C}\u{270F}\u{2712}\u{2714}\u{2716}\u{2728}\u{2733}-\u{2734}\u{2744}\u{2747}\u{274C}\u{274E}\u{2753}-\u{2755}\u{2757}\u{2764}\u{2795}-\u{2797}\u{27A1}\u{27B0}\u{2934}-\u{2935}\u{2B05}-\u{2B07}\u{2B1B}-\u{2B1C}\u{2B50}\u{2B55}\u{3030}\u{303D}\u{3297}\u{3299}\u{1F004}\u{1F0CF}\u{1F170}-\u{1F171}\u{1F17E}-\u{1F17F}\u{1F18E}\u{1F191}-\u{1F19A}\u{1F1E7}-\u{1F1EC}\u{1F1EE}-\u{1F1F0}\u{1F1F3}\u{1F1F5}\u{1F1F7}-\u{1F1FA}\u{1F201}-\u{1F202}\u{1F21A}\u{1F22F}\u{1F232}-\u{1F23A}\u{1F250}-\u{1F251}\u{1F300}-\u{1F320}\u{1F330}-\u{1F335}\u{1F337}-\u{1F37C}\u{1F380}-\u{1F393}\u{1F3A0}-\u{1F3C4}\u{1F3C6}-\u{1F3CA}\u{1F3E0}-\u{1F3F0}\u{1F400}-\u{1F43E}\u{1F440}\u{1F442}-\u{1F4F7}\u{1F4F9}-\u{1F4FC}\u{1F500}-\u{1F507}\u{1F509}-\u{1F53D}\u{1F550}-\u{1F567}\u{1F5FB}-\u{1F640}\u{1F645}-\u{1F64F}\u{1F680}-\u{1F68A}]+" {
didSet {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment