Skip to content

Commit 2d9b48c

Browse files
fix: fix the initialize
1 parent 03d1ada commit 2d9b48c

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

PlaygroundBook/Chapters/Chapter1.playgroundchapter/Pages/Intro.playgroundpage/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//:
1212
//: Before entering the playground, I want you to think about the difference between **Information** and **Knowledge**.
1313
//: - - -
14-
//: ## The difference between Information And Knowledge
14+
//: ## The difference between Information and Knowledge
1515
//: You can find a visual answer on the right side. Brifely speaking, knowledge can be achieved by establishing the relationship between entities on the basis of information. The entities are usually the real-world objects, events, situations or abstract concepts.
1616
//:
1717
//: Now that you know the difference between information and knowledge, I believe that you can understand knowledge graph as well.

PlaygroundBook/Chapters/Chapter1.playgroundchapter/Pages/Page3.playgroundpage/main.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ import PlaygroundSupport
2323
var userGraph: (Graph) -> Graph = { graph in
2424
//#-end-hidden-code
2525
//#-code-completion(everything, hide)
26-
//#-code-completion(identifier, hide, Page_Contents)
27-
26+
//#-code-completion(identifier, show, graph.addEntity(_ entity: Entity))
27+
//#-code-completion(identifier, show, graph.addEntities(_ entitiesToAdd: [Entity]))
28+
//#-code-completion(identifier, show, graph.addRelation(_ entity: Entity, to anotherEntity: Entity, relation: String))
29+
//#-code-completion(identifier, show, graph.updateRelation(_ firstEntity: Entity, to secondEntity: Entity, relation: String))
30+
//#-code-completion(identifier, show, graph.deleteEntity(_ entityToDelete: EntityID))
2831
//#-editable-code
2932
let Apple = Entity(text: "Apple")
3033
let Fruit = Entity(text: "Fruit")

PlaygroundBook/Modules/BookCore.playgroundmodule/Sources/Model/Entity.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ public struct Entity: Identifiable {
1919
var color: UIColor
2020

2121
public init(
22-
position: CGPoint = .zero,
23-
text: String = "",
24-
color: UIColor = UIColor.colors.randomItem()
22+
text: String = ""
2523
) {
26-
self.position = position
24+
self.position = .zero
2725
self.text = text
28-
self.color = color
26+
self.color = UIColor.colors.randomItem()
2927
}
3028

3129
}

PlaygroundBook/Modules/BookCore.playgroundmodule/Sources/Model/Graph.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ extension Graph {
133133

134134
@discardableResult func quickAddEntity(_ entity: Entity,_ entityName: String, at point: CGPoint? = nil, relation: String) -> Entity {
135135
let target = point ?? entity.position
136-
let child = Entity(position: target, text: entityName)
136+
var child = Entity(text: entityName)
137+
child.position = target
137138
addEntity(child)
138139
connect(entity, to: child, relation: relation)
139140
rebuildLinks()

0 commit comments

Comments
 (0)