Skip to content

Support for: Xcode 10.1 and Swift 4.2 #3

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

Open
wants to merge 3 commits into
base: flatten
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
5 changes: 2 additions & 3 deletions CRDTFramework/ORDT/ORDTDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func test()

let siteMap = SiteMap<UUID>()
let cursorMap = ORDTMap<LUID, OperationID>(withOwner: owner)
let causalTree = ORDTCausalTree<StringCharacterAtom>(owner: owner)

let pair = ORDTTuple2.init(cursorMap, siteMap)
let _ = ORDTCausalTree<StringCharacterAtom>(owner: owner)
let _ = ORDTTuple2.init(cursorMap, siteMap)
}
4 changes: 2 additions & 2 deletions CRDTFramework/StringRepresentation/CRDTTextEditing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ final class CRDTTextEditing: CvRDT, ApproxSizeable, NSCopying, Codable

public func incrementLamportTimestamp()
{
ct.weave.lamportTimestamp.increment()
cursorMap.lamportTimestamp.increment()
let _ = ct.weave.lamportTimestamp.increment()
let _ = cursorMap.lamportTimestamp.increment()
}

public static func ==(lhs: CRDTTextEditing, rhs: CRDTTextEditing) -> Bool
Expand Down
50 changes: 41 additions & 9 deletions CRDTPlayground.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@
remoteGlobalIDString = 4EFBCD451F5454DD0091F778;
remoteInfo = "CRDTFramework-OSX";
};
956EE0C6219EE01B00DC426E /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 4EFBCD181F5454B10091F778 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 4EFBCD1F1F5454B10091F778;
remoteInfo = CRDTPlayground;
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -622,6 +629,7 @@
);
dependencies = (
4EAB4778207FFF7000D5B189 /* PBXTargetDependency */,
956EE0C7219EE01B00DC426E /* PBXTargetDependency */,
);
name = ORDTTests;
productName = ORDTTests;
Expand Down Expand Up @@ -670,7 +678,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0900;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = "Alexei Baboulevitch";
TargetAttributes = {
4E64F17D1F98AAA800569170 = {
Expand All @@ -694,10 +702,13 @@
};
4EAB4770207FFF7000D5B189 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1010;
ProvisioningStyle = Automatic;
TestTargetID = 4EFBCD1F1F5454B10091F778;
};
4EFBCD1F1F5454B10091F778 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1010;
SystemCapabilities = {
com.apple.Sandbox = {
enabled = 0;
Expand Down Expand Up @@ -964,6 +975,11 @@
target = 4EFBCD451F5454DD0091F778 /* CRDTFramework-OSX */;
targetProxy = 4EAB4777207FFF7000D5B189 /* PBXContainerItemProxy */;
};
956EE0C7219EE01B00DC426E /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 4EFBCD1F1F5454B10091F778 /* CRDTPlayground */;
targetProxy = 956EE0C6219EE01B00DC426E /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
Expand Down Expand Up @@ -1010,8 +1026,8 @@
PRODUCT_BUNDLE_IDENTIFIER = net.archagon.CKCausalTreeTextCollabDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 1;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand All @@ -1032,8 +1048,8 @@
PRODUCT_BUNDLE_IDENTIFIER = net.archagon.CKCausalTreeTextCollabDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 1;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down Expand Up @@ -1061,6 +1077,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -1091,6 +1108,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -1101,6 +1119,7 @@
4EAB477A207FFF7000D5B189 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CODE_SIGN_STYLE = Automatic;
Expand All @@ -1112,13 +1131,15 @@
PRODUCT_BUNDLE_IDENTIFIER = "Alexei-Baboulevitch.ORDTTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CRDTPlayground.app/Contents/MacOS/CRDTPlayground";
};
name = Debug;
};
4EAB477B207FFF7000D5B189 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CODE_SIGN_STYLE = Automatic;
Expand All @@ -1130,7 +1151,8 @@
PRODUCT_BUNDLE_IDENTIFIER = "Alexei-Baboulevitch.ORDTTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CRDTPlayground.app/Contents/MacOS/CRDTPlayground";
};
name = Release;
};
Expand All @@ -1148,12 +1170,16 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
Expand Down Expand Up @@ -1203,12 +1229,16 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
Expand Down Expand Up @@ -1248,7 +1278,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "Alexei-Baboulevitch.CRDTPlayground";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -1265,7 +1295,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "Alexei-Baboulevitch.CRDTPlayground";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -1292,6 +1322,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -1321,6 +1352,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down
42 changes: 10 additions & 32 deletions CRDTPlayground/External/BinaryCodableExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,42 @@ import Foundation


// AB: addition
extension Dictionary: BinaryCodable {
extension Dictionary: BinaryCodable where Key:Codable, Value:Codable {
public func binaryEncode(to encoder: BinaryEncoder) throws {
guard Key.self is Encodable.Type else {
throw BinaryEncoder.Error.typeNotConformingToEncodable(Element.self)
}
guard Value.self is Encodable.Type else {
throw BinaryEncoder.Error.typeNotConformingToEncodable(Element.self)
}

try encoder.encode(self.count)
for pair in self {
try (pair.key as! Encodable).encode(to: encoder)
try (pair.value as! Encodable).encode(to: encoder)
try (pair.key).encode(to: encoder)
try (pair.value).encode(to: encoder)
}
}

public init(fromBinary decoder: BinaryDecoder) throws {
guard let binaryKeyElement = Key.self as? Decodable.Type else {
throw BinaryDecoder.Error.typeNotConformingToDecodable(Element.self)
}
guard let binaryValueElement = Value.self as? Decodable.Type else {
throw BinaryDecoder.Error.typeNotConformingToDecodable(Element.self)
}

let count = try decoder.decode(Int.self)
self.init()
self.reserveCapacity(count)
for _ in 0 ..< count {
let decodedKey = try binaryKeyElement.init(from: decoder)
let decodedValue = try binaryValueElement.init(from: decoder)
self[decodedKey as! Key] = (decodedValue as! Value)
let decodedKey = try Key.init(from: decoder)
let decodedValue = try Value.init(from: decoder)
self[decodedKey] = (decodedValue)
}
}
}

extension Array: BinaryCodable {
extension Array: BinaryCodable where Element:Codable {
public func binaryEncode(to encoder: BinaryEncoder) throws {
guard Element.self is Encodable.Type else {
throw BinaryEncoder.Error.typeNotConformingToEncodable(Element.self)
}

try encoder.encode(self.count)
for element in self {
try (element as! Encodable).encode(to: encoder)
try (element as Encodable).encode(to: encoder)
}
}

public init(fromBinary decoder: BinaryDecoder) throws {
guard let binaryElement = Element.self as? Decodable.Type else {
throw BinaryDecoder.Error.typeNotConformingToDecodable(Element.self)
}

let count = try decoder.decode(Int.self)
self.init()
self.reserveCapacity(count)
for _ in 0 ..< count {
let decoded = try binaryElement.init(from: decoder)
self.append(decoded as! Element)
let decoded = try Element.init(from: decoder)
self.append(decoded)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,10 @@ class CausalTreeBezierWrapper
}
}.lazy

let filterIds = filter.map
let filterIds : [TempShapeId] = filter.map
{
return WeaveIndex($0.offset)
}.lazy
} // .lazy

return AnyCollection(filterIds)
}
Expand Down Expand Up @@ -484,7 +484,7 @@ class CausalTreeBezierWrapper
let shape = crdt.weave.addAtom(withValue: .shape, causedBy: slice[Int(shapeParent)].id)!
let root = crdt.weave.addAtom(withValue: .null, causedBy: shape.0)!
let startSentinel = crdt.weave.addAtom(withValue: .pointSentinelStart, causedBy: root.0)!
let endSentinel = crdt.weave.addAtom(withValue: .pointSentinelEnd, causedBy: startSentinel.0)!
let _ = crdt.weave.addAtom(withValue: .pointSentinelEnd, causedBy: startSentinel.0)!
let firstPoint = crdt.weave.addAtom(withValue: .point(pos: NSMakePoint(x, y)), causedBy: startSentinel.0)!

updateAttributes(rounded: arc4random_uniform(2) == 0, forPoint: firstPoint.1)
Expand Down Expand Up @@ -549,7 +549,7 @@ class CausalTreeBezierWrapper
let maxLength: Scalar = 30
let maxCCAngle: Scalar = 70
let maxCAngle: Scalar = 20
let offset: CGFloat = 4
let _: CGFloat = 4

let pointIndex = pointId
let shapeIndex = shapeForPoint(pointIndex)
Expand Down Expand Up @@ -613,7 +613,7 @@ class CausalTreeBezierWrapper
vec = vec.rotated(by: angle * ((2*Scalar.pi)/360))

let tempNewPoint = NSMakePoint(point.x + CGFloat(vec.x), point.y + CGFloat(vec.y))
if let b = bounds
if let _ = bounds
{
// let t = transform(forOperations: operations(forShape: shapeIndex)).inverted()
// let tBounds = b.applying(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,23 @@ class CausalTreeDrawEditingView: NSView, CausalTreeContentView
// MARK: - Lifecycle -
//////////////////////

let foregroundColorAttributes = [NSAttributedString.Key.foregroundColor: NSColor.black]

required init(frame frameRect: NSRect, crdt: CausalTreeBezierT)
{
self.model = CausalTreeBezierWrapper(crdt: crdt)

self.buttonStack = NSStackView()
self.buttonStack = NSStackView()
self.b1 = NSButton(title: "New Shape", target: nil, action: nil)
self.b1.attributedTitle = NSAttributedString(string: self.b1.title, attributes: foregroundColorAttributes)
self.b3 = NSButton(title: "Append Point", target: nil, action: nil)
self.b3.attributedTitle = NSAttributedString(string: self.b3.title, attributes: foregroundColorAttributes)
self.b4 = NSButton(title: "Delete Point", target: nil, action: nil)
self.b4.attributedTitle = NSAttributedString(string: self.b4.title, attributes: foregroundColorAttributes)
self.b2 = NSButton(title: "Cycle Shape Color", target: nil, action: nil)
self.b2.attributedTitle = NSAttributedString(string: self.b2.title, attributes: foregroundColorAttributes)
self.b5 = NSButton(title: "Cycle Point Round", target: nil, action: nil)

self.b5.attributedTitle = NSAttributedString(string: self.b5.title, attributes: foregroundColorAttributes)
super.init(frame: frameRect)

self.wantsLayer = true
Expand Down Expand Up @@ -196,10 +202,12 @@ class CausalTreeDrawEditingView: NSView, CausalTreeContentView
if model.isLastPoint(sel)
{
self.b3.title = "Append Point"
self.b3.attributedTitle = NSAttributedString(string: self.b3.title, attributes: foregroundColorAttributes)
}
else
{
self.b3.title = "Insert Point"
self.b3.attributedTitle = NSAttributedString(string: self.b3.title, attributes: foregroundColorAttributes)
}
}
}
Expand Down Expand Up @@ -295,7 +303,7 @@ class CausalTreeDrawEditingView: NSView, CausalTreeContentView
NSColor.black.setStroke()
model.attributes(forShape: s).setFill()
path.lineWidth = 1.5
path.lineJoinStyle = .roundLineJoinStyle
path.lineJoinStyle = .round
path.close()

path.stroke()
Expand Down
Loading