Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I need to access all UIBezierPath. Please merge with this. #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion SwiftSVG.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Strauss LLC";
TargetAttributes = {
396A8E431B3D2036001986AF = {
Expand All @@ -303,6 +303,7 @@
};
39B8D88B1B3C3283009DAF60 = {
CreatedOnToolsVersion = 6.3.2;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -460,6 +461,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -505,12 +507,14 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.sixpolys.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
39B8D89F1B3C3284009DAF60 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
Expand All @@ -529,6 +533,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.straussmade.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -538,6 +543,7 @@
39B8D8A01B3C3284009DAF60 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
Expand All @@ -553,6 +559,8 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.straussmade.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -572,8 +580,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -582,6 +592,7 @@
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -615,15 +626,18 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions SwiftSVG/CAShapeLayer+SVG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ extension CAShapeLayer {
public convenience init(pathString: String) {
self.init()
let svgPath = UIBezierPath(pathString: pathString)
self.path = svgPath.CGPath
self.path = svgPath.cgPath
}

public convenience init(SVGURL: NSURL) {
public convenience init(SVGURL: URL) {
self.init()
_ = SVGParser(SVGURL: SVGURL, containerLayer: self)
}
Expand Down
4 changes: 2 additions & 2 deletions SwiftSVG/Dictionary+KeyForValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

import Foundation

public func allKeysForValue<K, V: Equatable>(dict: [K: V], valueToMatch: V) -> [K]? {
public func allKeysForValue<K, V: Equatable>(_ dict: [K: V], valueToMatch: V) -> [K]? {

let possibleValues = dict.filter ({ (key, value) -> Bool in
return value == valueToMatch
Expand All @@ -49,4 +49,4 @@ public func allKeysForValue<K, V: Equatable>(dict: [K: V], valueToMatch: V) -> [
return possibleValues
}
return nil
}
}
8 changes: 4 additions & 4 deletions SwiftSVG/NSObject+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ extension NSObject {

// iterate each objc_property_t struct
for i in 0..<count {
let property = properties[Int(i)];
let property = properties?[Int(i)];

// retrieve the property name by calling property_getName function
let cname = property_getName(property);

// convert the c string into a Swift string
let name = String.fromCString(cname);
results.append(name!);
let name = String(cString: cname!);
results.append(name);
}

// release objc_property_t structs
Expand All @@ -78,4 +78,4 @@ extension NSObject {
return classString
}

}
}
16 changes: 8 additions & 8 deletions SwiftSVG/SVGParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,47 +48,47 @@ private var tagMapping: [String: String] = [
didSet {
if let pathStringToParse = d {
self.path = pathStringToParse.pathFromSVGString()
self.shapeLayer.path = self.path.CGPath
self.shapeLayer.path = self.path.cgPath
}
}
}

var fill: String? {
didSet {
if let hexFill = fill {
self.shapeLayer.fillColor = UIColor(hexString: hexFill).CGColor
self.shapeLayer.fillColor = UIColor(hexString: hexFill).cgColor
}
}
}
}

@objc(SVGElement) private class SVGElement: NSObject { }

public class SVGParser : NSObject, NSXMLParserDelegate {
public class SVGParser : NSObject, XMLParserDelegate {

private var elementStack = Stack<NSObject>()

public var containerLayer: CALayer?
public var shouldParseSinglePathOnly = false
internal var paths = [UIBezierPath]()

convenience init(SVGURL: NSURL, containerLayer: CALayer? = nil, shouldParseSinglePathOnly: Bool = false) {
convenience init(SVGURL: URL, containerLayer: CALayer? = nil, shouldParseSinglePathOnly: Bool = false) {

self.init()

if let layer = containerLayer {
self.containerLayer = layer
}

if let xmlParser = NSXMLParser(contentsOfURL: SVGURL) {
if let xmlParser = XMLParser(contentsOf: SVGURL) {
xmlParser.delegate = self
xmlParser.parse()
} else {
assert(false, "Couldn't initialize parser. Check your resource and make sure the supplied URL is correct")
}
}

public func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
public func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {

if let newElement = tagMapping[elementName] {

Expand Down Expand Up @@ -119,11 +119,11 @@ public class SVGParser : NSObject, NSXMLParserDelegate {
}


public func parser(parser: NSXMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
public func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
if let lastItem = self.elementStack.last {
if let keyForValue = allKeysForValue(tagMapping,valueToMatch: lastItem.classNameAsString())?.first {
if elementName == keyForValue {
self.elementStack.pop()
_ = self.elementStack.pop()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions SwiftSVG/SVGView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public class SVGView : UIView {
if let thisName = SVGName {

#if !TARGET_INTERFACE_BUILDER
let bundle = NSBundle.mainBundle()
let bundle = Bundle.main
#else
let bundle = NSBundle(forClass: self.dynamicType)
#endif

if let url = bundle.URLForResource(thisName, withExtension: "svg") {
if let url = bundle.url(forResource: thisName, withExtension: "svg") {
self.shapeLayer = CAShapeLayer(SVGURL: url)
if self.shapeLayer.superlayer == nil {
self.nonOptionalLayer.addSublayer(self.shapeLayer)
Expand Down
4 changes: 2 additions & 2 deletions SwiftSVG/Stack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Foundation
struct Stack<T> {
var items = [T]()

mutating func push(itemToPush: T) {
mutating func push(_ itemToPush: T) {
self.items.append(itemToPush)
}

Expand Down Expand Up @@ -74,4 +74,4 @@ extension Stack {
return nil
}
}
}
}
Loading