1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-10-05 16:57:12 +03:00

moved to swift 5

This commit is contained in:
Anton Marunko 2019-03-26 17:58:13 +06:00
parent 51523955c1
commit bb3cb69616
25 changed files with 98 additions and 91 deletions

View File

@ -548,7 +548,7 @@ public enum XMLIndexer {
/// All child elements from the currently indexed level
public var children: [XMLIndexer] {
var list = [XMLIndexer]()
for elem in all.flatMap({ $0.element }) {
for elem in all.compactMap({ $0.element }) {
for elem in elem.xmlChildren {
list.append(XMLIndexer(elem))
}
@ -817,7 +817,7 @@ public class XMLElement: XMLContent {
var index: Int
var xmlChildren: [XMLElement] {
return children.flatMap { $0 as? XMLElement }
return children.compactMap { $0 as? XMLElement }
}
/**

View File

@ -29,7 +29,7 @@ Pod::Spec.new do |s|
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.12"
s.requires_arc = true
s.swift_version = "4.2"
s.swift_version = "5.0"
s.source_files = [
'Source/**/*.swift'

View File

@ -1706,7 +1706,7 @@
};
buildConfigurationList = 57FCD2661D76EA4600CC0FB6 /* Build configuration list for PBXProject "Macaw" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
@ -1996,7 +1996,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint autocorrect --format\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
shellScript = "if which swiftlint >/dev/null; then\n swiftlint autocorrect --format\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */
@ -2331,7 +2331,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = macosx;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
};
name = Debug;
@ -2356,7 +2356,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = macosx;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
};
name = Release;
@ -2503,7 +2503,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
};
name = Debug;
@ -2528,7 +2528,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
};
name = Release;
@ -2550,7 +2550,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
VALID_ARCHS = "x86_64 i386";
};
@ -2573,7 +2573,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
VALID_ARCHS = "x86_64 i386";
};

View File

@ -133,8 +133,9 @@ class BasicAnimation: Animation {
// MARK: - Hashable
extension BasicAnimation: Hashable {
public var hashValue: Int {
return ID.hashValue
func hash(into hasher: inout Hasher) {
hasher.combine(ID)
}
public static func == (lhs: BasicAnimation, rhs: BasicAnimation) -> Bool {

View File

@ -82,7 +82,7 @@ internal class AnimationSequence: BasicAnimation {
}
public extension Sequence where Iterator.Element: Animation {
public func sequence(delay: Double = 0.0) -> Animation {
func sequence(delay: Double = 0.0) -> Animation {
var sequence = [BasicAnimation]()
self.forEach { animation in

View File

@ -82,7 +82,7 @@ internal class CombineAnimation: BasicAnimation {
}
public extension Sequence where Iterator.Element: Animation {
public func combine(delay: Double = 0.0, node: Node? = .none, toNodes: [Node] = []) -> Animation {
func combine(delay: Double = 0.0, node: Node? = .none, toNodes: [Node] = []) -> Animation {
var toCombine = [BasicAnimation]()
self.forEach { animation in

View File

@ -40,32 +40,32 @@ internal class ContentsAnimation: AnimationImpl<[Node]> {
public extension AnimatableVariable where T: ContentsInterpolation {
public func animation(_ f: @escaping (Double) -> [Node]) -> Animation {
func animation(_ f: @escaping (Double) -> [Node]) -> Animation {
let group = node! as! Group
return ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: 1.0, delay: 0.0, autostart: false)
}
public func animation(_ f: @escaping ((Double) -> [Node]), during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(_ f: @escaping ((Double) -> [Node]), during: Double = 1.0, delay: Double = 0.0) -> Animation {
let group = node! as! Group
return ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: during, delay: delay, autostart: false)
}
public func animation(during: Double = 1.0, delay: Double = 0.0, _ f: @escaping ((Double) -> [Node])) -> Animation {
func animation(during: Double = 1.0, delay: Double = 0.0, _ f: @escaping ((Double) -> [Node])) -> Animation {
let group = node! as! Group
return ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: during, delay: delay, autostart: false)
}
public func animate(_ f: @escaping (Double) -> [Node]) {
func animate(_ f: @escaping (Double) -> [Node]) {
let group = node! as! Group
_ = ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: 1.0, delay: 0.0, autostart: true)
}
public func animate(_ f: @escaping ((Double) -> [Node]), during: Double = 1.0, delay: Double = 0.0) {
func animate(_ f: @escaping ((Double) -> [Node]), during: Double = 1.0, delay: Double = 0.0) {
let group = node! as! Group
_ = ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: during, delay: delay, autostart: true)
}
public func animate(during: Double = 1.0, delay: Double = 0.0, _ f: @escaping ((Double) -> [Node])) {
func animate(during: Double = 1.0, delay: Double = 0.0, _ f: @escaping ((Double) -> [Node])) {
let group = node! as! Group
_ = ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: during, delay: delay, autostart: true)
}

View File

@ -38,19 +38,19 @@ class MorphingAnimation: AnimationImpl<Locus> {
public typealias MorphingAnimationDescription = AnimationDescription<Locus>
public extension AnimatableVariable where T: LocusInterpolation {
public func animate(_ desc: MorphingAnimationDescription) {
func animate(_ desc: MorphingAnimationDescription) {
_ = MorphingAnimation(animatedNode: node as! Shape, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: true)
}
public func animation(_ desc: MorphingAnimationDescription) -> Animation {
func animation(_ desc: MorphingAnimationDescription) -> Animation {
return MorphingAnimation(animatedNode: node as! Shape, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
}
public func animate(from: Locus? = nil, to: Locus, during: Double = 1.0, delay: Double = 0.0) {
func animate(from: Locus? = nil, to: Locus, during: Double = 1.0, delay: Double = 0.0) {
self.animate(((from ?? (node as! Shape).form) >> to).t(during, delay: delay))
}
public func animation(from: Locus? = nil, to: Locus, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(from: Locus? = nil, to: Locus, during: Double = 1.0, delay: Double = 0.0) -> Animation {
if let safeFrom = from {
return self.animation((safeFrom >> to).t(during, delay: delay))
}
@ -67,7 +67,7 @@ public extension AnimatableVariable where T: LocusInterpolation {
return MorphingAnimation(animatedNode: self.node as! Shape, factory: factory, animationDuration: during, delay: delay)
}
public func animation(_ f: @escaping (Double) -> Locus, during: Double, delay: Double = 0.0) -> Animation {
func animation(_ f: @escaping (Double) -> Locus, during: Double, delay: Double = 0.0) -> Animation {
return MorphingAnimation(animatedNode: node as! Shape, valueFunc: f, animationDuration: during, delay: delay)
}
@ -76,7 +76,7 @@ public extension AnimatableVariable where T: LocusInterpolation {
// MARK: - Group
public extension AnimatableVariable where T: ContentsInterpolation {
public func animation(from: Group? = nil, to: [Node], during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(from: Group? = nil, to: [Node], during: Double = 1.0, delay: Double = 0.0) -> Animation {
var fromNode = node as! Group
if let passedFromNode = from {
fromNode = passedFromNode
@ -85,7 +85,7 @@ public extension AnimatableVariable where T: ContentsInterpolation {
return CombineAnimation(animations: [], during: during, node: fromNode, toNodes: to)
}
public func animate(from: Group? = nil, to: [Node], during: Double = 1.0, delay: Double = 0.0) {
func animate(from: Group? = nil, to: [Node], during: Double = 1.0, delay: Double = 0.0) {
animation(from: from, to: to, during: during, delay: delay).play()
}
}

View File

@ -49,19 +49,19 @@ internal class OpacityAnimation: AnimationImpl<Double> {
public typealias OpacityAnimationDescription = AnimationDescription<Double>
public extension AnimatableVariable where T: DoubleInterpolation {
public func animate(_ desc: OpacityAnimationDescription) {
func animate(_ desc: OpacityAnimationDescription) {
_ = OpacityAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: true)
}
public func animation(_ desc: OpacityAnimationDescription) -> Animation {
func animation(_ desc: OpacityAnimationDescription) -> Animation {
return OpacityAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
}
public func animate(from: Double? = nil, to: Double, during: Double = 1.0, delay: Double = 0.0) {
func animate(from: Double? = nil, to: Double, during: Double = 1.0, delay: Double = 0.0) {
self.animate(((from ?? node!.opacity) >> to).t(during, delay: delay))
}
public func animation(from: Double? = nil, to: Double, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(from: Double? = nil, to: Double, during: Double = 1.0, delay: Double = 0.0) -> Animation {
if let safeFrom = from {
return self.animation((safeFrom >> to).t(during, delay: delay))
}
@ -71,7 +71,7 @@ public extension AnimatableVariable where T: DoubleInterpolation {
return OpacityAnimation(animatedNode: self.node!, factory: factory, animationDuration: during, delay: delay)
}
public func animation(_ f: @escaping ((Double) -> Double), during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(_ f: @escaping ((Double) -> Double), during: Double = 1.0, delay: Double = 0.0) -> Animation {
return OpacityAnimation(animatedNode: node!, valueFunc: f, animationDuration: during, delay: delay)
}

View File

@ -69,7 +69,7 @@ class ShapeAnimation: AnimationImpl<Shape> {
}
public extension AnimatableVariable {
public func animate<T: Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
func animate<T: Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
let shape = node as! Shape
var safeFrom = from
@ -89,7 +89,7 @@ public extension AnimatableVariable {
_ = ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: true)
}
public func animation<T: Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation<T: Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
let shape = node as! Shape
var safeFrom = from
@ -111,7 +111,7 @@ public extension AnimatableVariable {
}
public extension AnimatableVariable {
public func animate<T: Fill>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
func animate<T: Fill>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
let shape = node as! Shape
var safeFrom = from
@ -131,7 +131,7 @@ public extension AnimatableVariable {
_ = ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: true)
}
public func animation<T: Fill>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation<T: Fill>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
let shape = node as! Shape
var safeFrom = from

View File

@ -65,29 +65,29 @@ internal class TransformAnimation: AnimationImpl<Transform> {
public typealias TransformAnimationDescription = AnimationDescription<Transform>
public extension AnimatableVariable where T: TransformInterpolation {
public func animate(_ desc: TransformAnimationDescription) {
func animate(_ desc: TransformAnimationDescription) {
_ = TransformAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: true)
}
public func animation(_ desc: TransformAnimationDescription) -> Animation {
func animation(_ desc: TransformAnimationDescription) -> Animation {
return TransformAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
}
public func animate(from: Transform? = nil, to: Transform, during: Double = 1.0, delay: Double = 0.0) {
func animate(from: Transform? = nil, to: Transform, during: Double = 1.0, delay: Double = 0.0) {
self.animate(((from ?? node!.place) >> to).t(during, delay: delay))
}
public func animate(angle: Double, x: Double? = .none, y: Double? = .none, during: Double = 1.0, delay: Double = 0.0) {
func animate(angle: Double, x: Double? = .none, y: Double? = .none, during: Double = 1.0, delay: Double = 0.0) {
let animation = self.animation(angle: angle, x: x, y: y, during: during, delay: delay)
animation.play()
}
public func animate(along path: Path, during: Double = 1.0, delay: Double = 0.0) {
func animate(along path: Path, during: Double = 1.0, delay: Double = 0.0) {
let animation = self.animation(along: path, during: during, delay: delay)
animation.play()
}
public func animation(from: Transform? = nil, to: Transform, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(from: Transform? = nil, to: Transform, during: Double = 1.0, delay: Double = 0.0) -> Animation {
if let safeFrom = from {
return self.animation((safeFrom >> to).t(during, delay: delay))
}
@ -98,11 +98,11 @@ public extension AnimatableVariable where T: TransformInterpolation {
return TransformAnimation(animatedNode: self.node!, factory: factory, animationDuration: during, delay: delay)
}
public func animation(_ f: @escaping ((Double) -> Transform), during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(_ f: @escaping ((Double) -> Transform), during: Double = 1.0, delay: Double = 0.0) -> Animation {
return TransformAnimation(animatedNode: node!, valueFunc: f, animationDuration: during, delay: delay)
}
public func animation(angle: Double, x: Double? = .none, y: Double? = .none, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(angle: Double, x: Double? = .none, y: Double? = .none, during: Double = 1.0, delay: Double = 0.0) -> Animation {
let bounds = node!.bounds!
let factory = { () -> (Double) -> Transform in { t in
@ -130,7 +130,7 @@ public extension AnimatableVariable where T: TransformInterpolation {
return TransformAnimation(animatedNode: self.node!, factory: factory, animationDuration: during, delay: delay)
}
public func animation(along path: Path, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(along path: Path, during: Double = 1.0, delay: Double = 0.0) -> Animation {
let factory = { () -> (Double) -> Transform in { (t: Double) in Transform.identity }
}

View File

@ -1,8 +1,8 @@
// TODO: Implement better hash
extension Node: Hashable {
public var hashValue: Int {
return Unmanaged.passUnretained(self).toOpaque().hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(Unmanaged.passUnretained(self).toOpaque())
}
}
@ -11,8 +11,8 @@ public func == (lhs: Node, rhs: Node) -> Bool {
}
extension NodeRenderer: Hashable {
public var hashValue: Int {
return Unmanaged.passUnretained(self).toOpaque().hashValue
func hash(into hasher: inout Hasher) {
hasher.combine(Unmanaged.passUnretained(self).toOpaque())
}
}

View File

@ -1,11 +1,11 @@
extension Transform: Hashable {
public var hashValue: Int {
return m11.hashValue ^
m12.hashValue ^
m21.hashValue ^
m22.hashValue ^
dx.hashValue ^
dy.hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(m11)
hasher.combine(m12)
hasher.combine(m21)
hasher.combine(m22)
hasher.combine(dx)
hasher.combine(dy)
}
}

View File

@ -37,7 +37,7 @@ open class Variable<T> {
let handler = ChangeHandler<T>(f)
handlers.append(handler)
return Disposable { [weak self, unowned handler] in
guard let index = self?.handlers.index(of: handler) else {
guard let index = self?.handlers.firstIndex(of: handler) else {
return
}

View File

@ -10,7 +10,7 @@ import Foundation
import CoreGraphics
public extension MacawView {
public func toPDF(size: CGSize, path: URL) {
func toPDF(size: CGSize, path: URL) {
let currentColor = backgroundColor
backgroundColor = MColor.white
defer {

View File

@ -46,6 +46,10 @@ open class ContentLayout {
return of(scaling: .doNothing, xAlign: .min, yAlign: .max)
case .bottomRight:
return of(scaling: .doNothing, xAlign: .max, yAlign: .max)
#if os(iOS)
@unknown default:
return .none
#endif
}
}

View File

@ -117,7 +117,7 @@ open class Group: Node {
}
public extension Array where Element: Node {
public func group( place: Transform = Transform.identity, opaque: Bool = true, opacity: Double = 1, clip: Locus? = nil, effect: Effect? = nil, visible: Bool = true, tag: [String] = []) -> Group {
func group( place: Transform = Transform.identity, opaque: Bool = true, opacity: Double = 1, clip: Locus? = nil, effect: Effect? = nil, visible: Bool = true, tag: [String] = []) -> Group {
return Group(contents: self, place: place, opaque: opaque, opacity: opacity, clip: clip, effect: effect, visible: visible, tag: tag)
}
}

View File

@ -73,7 +73,7 @@ open class Node: Drawable {
touchPressedHandlers.append(handler)
return Disposable { [weak self, unowned handler] in
guard let index = self?.touchPressedHandlers.index(of: handler) else {
guard let index = self?.touchPressedHandlers.firstIndex(of: handler) else {
return
}
@ -86,7 +86,7 @@ open class Node: Drawable {
touchMovedHandlers.append(handler)
return Disposable { [weak self, unowned handler] in
guard let index = self?.touchMovedHandlers.index(of: handler) else {
guard let index = self?.touchMovedHandlers.firstIndex(of: handler) else {
return
}
@ -99,7 +99,7 @@ open class Node: Drawable {
touchReleasedHandlers.append(handler)
return Disposable { [weak self, unowned handler] in
guard let index = self?.touchReleasedHandlers.index(of: handler) else {
guard let index = self?.touchReleasedHandlers.firstIndex(of: handler) else {
return
}
@ -116,7 +116,7 @@ open class Node: Drawable {
}
return Disposable { [weak self, unowned handler] in
guard let index = self?.tapHandlers[tapCount]?.index(of: handler) else {
guard let index = self?.tapHandlers[tapCount]?.firstIndex(of: handler) else {
return
}
@ -129,7 +129,7 @@ open class Node: Drawable {
longTapHandlers.append(handler)
return Disposable { [weak self, unowned handler] in
guard let index = self?.longTapHandlers.index(of: handler) else {
guard let index = self?.longTapHandlers.firstIndex(of: handler) else {
return
}
@ -142,7 +142,7 @@ open class Node: Drawable {
panHandlers.append(handler)
return Disposable { [weak self, unowned handler] in
guard let index = self?.panHandlers.index(of: handler) else {
guard let index = self?.panHandlers.firstIndex(of: handler) else {
return
}
@ -155,7 +155,7 @@ open class Node: Drawable {
rotateHandlers.append(handler)
return Disposable { [weak self, unowned handler] in
guard let index = self?.rotateHandlers.index(of: handler) else {
guard let index = self?.rotateHandlers.firstIndex(of: handler) else {
return
}
@ -168,7 +168,7 @@ open class Node: Drawable {
pinchHandlers.append(handler)
return Disposable { [weak self, unowned handler] in
guard let index = self?.pinchHandlers.index(of: handler) else {
guard let index = self?.pinchHandlers.firstIndex(of: handler) else {
return
}

View File

@ -52,6 +52,8 @@ extension MBezierPath {
case .closePath:
path.closeSubpath()
@unknown default:
fatalError("Type of element undefined")
}
}

View File

@ -268,7 +268,7 @@ class NodeRenderer {
if let groupRenderer = parentRenderer as? GroupRenderer, let group = groupRenderer.node() as? Group {
var contents = group.contents
var indexToInsert = 0
if let index = contents.index(of: node) {
if let index = contents.firstIndex(of: node) {
contents.remove(at: index)
indexToInsert = index
}

View File

@ -70,7 +70,7 @@ class CAAnimationDelegateImpl: NSObject, CAAnimationDelegate {
public extension CAAnimation {
/// A block (closure) object to be executed when the animation starts. This block has no return value and takes no argument.
public var start: (() -> Void)? {
var start: (() -> Void)? {
set {
if let animationDelegate = delegate as? CAAnimationDelegateImpl {
animationDelegate.start = newValue
@ -91,7 +91,7 @@ public extension CAAnimation {
}
/// A block (closure) object to be executed when the animation ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished.
public var completion: ((Bool) -> Void)? {
var completion: ((Bool) -> Void)? {
set {
if let animationDelegate = delegate as? CAAnimationDelegateImpl {
animationDelegate.completion = newValue
@ -112,7 +112,7 @@ public extension CAAnimation {
}
/// A block (closure) object to be executed when the animation is animating. This block has no return value and takes a single CGFloat argument that indicates the progress of the animation (From 0 ..< 1)
public var animating: ((CGFloat) -> Void)? {
var animating: ((CGFloat) -> Void)? {
set {
if let animationDelegate = delegate as? CAAnimationDelegateImpl {
animationDelegate.animating = newValue
@ -133,7 +133,7 @@ public extension CAAnimation {
}
/// Alias to `animating`
public var progress: ((CGFloat) -> Void)? {
var progress: ((CGFloat) -> Void)? {
set {
animating = newValue
}

View File

@ -13,7 +13,7 @@ import AppKit
public extension Color {
public func toCG() -> CGColor {
func toCG() -> CGColor {
let red = CGFloat(Double(r()) / 255.0)
let green = CGFloat(Double(g()) / 255.0)
let blue = CGFloat(Double(b()) / 255.0)
@ -25,7 +25,7 @@ public extension Color {
public extension Transform {
public func toCG() -> CGAffineTransform {
func toCG() -> CGAffineTransform {
return CGAffineTransform(a: CGFloat(m11), b: CGFloat(m12), c: CGFloat(m21),
d: CGFloat(m22), tx: CGFloat(dx), ty: CGFloat(dy))
}
@ -34,7 +34,7 @@ public extension Transform {
public extension LineJoin {
public func toCG() -> CGLineJoin {
func toCG() -> CGLineJoin {
switch self {
case .round:
return .round
@ -49,7 +49,7 @@ public extension LineJoin {
public extension LineCap {
public func toCG() -> CGLineCap {
func toCG() -> CGLineCap {
switch self {
case .round:
return CGLineCap.round
@ -64,7 +64,7 @@ public extension LineCap {
public extension Rect {
public func toCG() -> CGRect {
func toCG() -> CGRect {
return CGRect(x: self.x, y: self.y, width: self.w, height: self.h)
}
@ -76,7 +76,7 @@ public extension Rect {
public extension CGRect {
public func toMacaw() -> Rect {
func toMacaw() -> Rect {
return Rect(x: Double(origin.x),
y: Double(origin.y),
w: Double(size.width),
@ -87,7 +87,7 @@ public extension CGRect {
public extension Size {
public func toCG() -> CGSize {
func toCG() -> CGSize {
return CGSize(width: self.w, height: self.h)
}
@ -95,7 +95,7 @@ public extension Size {
public extension CGSize {
public func toMacaw() -> Size {
func toMacaw() -> Size {
return Size(w: Double(width),
h: Double(height))
}
@ -104,7 +104,7 @@ public extension CGSize {
public extension Point {
public func toCG() -> CGPoint {
func toCG() -> CGPoint {
return CGPoint(x: self.x, y: self.y)
}
@ -112,7 +112,7 @@ public extension Point {
public extension CGPoint {
public func toMacaw() -> Point {
func toMacaw() -> Point {
return Point(x: Double(x), y: Double(y))
}
@ -120,7 +120,7 @@ public extension CGPoint {
public extension Locus {
public func toCGPath() -> CGPath {
func toCGPath() -> CGPath {
return RenderUtils.toCGPath(self)
}
@ -128,14 +128,14 @@ public extension Locus {
public extension CGAffineTransform {
public func toMacaw() -> Transform {
func toMacaw() -> Transform {
return Transform(m11: Double(a), m12: Double(b), m21: Double(c), m22: Double(d), dx: Double(tx), dy: Double(ty))
}
}
public extension Node {
public func toNativeImage(size: Size, layout: ContentLayout = .of()) -> MImage {
func toNativeImage(size: Size, layout: ContentLayout = .of()) -> MImage {
let renderer = RenderUtils.createNodeRenderer(self, view: nil, animationCache: nil)
let rect = size.rect()

View File

@ -15,7 +15,7 @@ import UIKit
var imagesMap = [String: MImage]()
public extension MImage {
public func image( xAlign: Align = .min, yAlign: Align = .min, aspectRatio: AspectRatio = .none, w: Int = 0, h: Int = 0, place: Transform = Transform.identity, opaque: Bool = true, opacity: Double = 1, clip: Locus? = nil, effect: Effect? = nil, visible: Bool = true, tag: [String] = []) -> Image {
func image( xAlign: Align = .min, yAlign: Align = .min, aspectRatio: AspectRatio = .none, w: Int = 0, h: Int = 0, place: Transform = Transform.identity, opaque: Bool = true, opacity: Double = 1, clip: Locus? = nil, effect: Effect? = nil, visible: Bool = true, tag: [String] = []) -> Image {
var oldId: String?
for key in imagesMap.keys where self === imagesMap[key] {

View File

@ -287,7 +287,7 @@ open class MacawView: MView, MGestureRecognizerDelegate {
var points = [TouchPoint]()
for initialTouch in initialTouches {
guard let currentIndex = touches.index(of: initialTouch) else {
guard let currentIndex = touches.firstIndex(of: initialTouch) else {
continue
}
let currentTouch = touches[currentIndex]
@ -332,7 +332,7 @@ open class MacawView: MView, MGestureRecognizerDelegate {
let touchEvent = TouchEvent(node: node, points: [point])
node.handleTouchReleased(touchEvent)
if let index = touchesOfNode[node]?.index(of: touch) {
if let index = touchesOfNode[node]?.firstIndex(of: touch) {
touchesOfNode[node]?.remove(at: index)
// swiftlint:disable empty_count
if let count = touchesOfNode[node]?.count, count == 0 {

View File

@ -9,8 +9,8 @@ class MTouchEvent: Hashable {
self.id = id
}
public var hashValue: Int {
return id.hashValue
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
public static func == (lhs: MTouchEvent, rhs: MTouchEvent) -> Bool {