Skip to content

Instantly share code, notes, and snippets.

View SiarheiFedartsou's full-sized avatar

Siarhei Fedartsou SiarheiFedartsou

View GitHub Profile
:method: POST
:scheme: https
:path: /v1/motion-records?activityId=1311&deviceId=device_id&deviceMotionRecordId=device_motion_record_id&motionTypeId=1010&movementCount=10&name=record_name&status=COMPLETED
:authority: exp-ais-milfei.octonion.com
accept: */*
content-type: multipart/form-data; boundary=alamofire.boundary.9b685607dd401d7c
authorization: bearer 482315ba-4ad9-4749-aa78-77b7198d1376
accept-encoding: gzip;q=1.0, compress;q=0.5
user-agent: DataMiningApplication/1.0 (com.octonion.inhouse.DataMiningApplication; build:1; iOS 11.3.0) Alamofire/4.7.1
content-length: 31837
:method: POST
:scheme: https
:path: /v1/motion-records?activityId=784&deviceId=device_id&deviceMotionRecordId=device_motion_record_id&motionTypeId=605&movementCount=10&name=&status=completed
:authority: exp-ais-milfei.octonion.com
accept: */*
content-type: multipart/form-data; boundary=alamofire.boundary.aef675936694deaa
authorization: bearer e26150d7-4829-4b43-b9ba-93aac9f26db0
accept-encoding: gzip;q=1.0, compress;q=0.5
user-agent: DataMiningApplication/1.0 (com.octonion.inhouse.DataMiningApplication; build:1; iOS 11.3.0) Alamofire/4.7.1
content-length: 19053
:method: POST
:scheme: https
:path: /v1/motion-records?activityId=784&motionTypeId=605&movementCount=10&name=
:authority: exp-ais-milfei.octonion.com
accept: */*
content-type: multipart/form-data; boundary=alamofire.boundary.efac4053b38a155d
authorization: bearer e26150d7-4829-4b43-b9ba-93aac9f26db0
accept-encoding: gzip;q=1.0, compress;q=0.5
user-agent: DataMiningApplication/1.0 (com.octonion.inhouse.DataMiningApplication; build:1; iOS 11.3.0) Alamofire/4.7.1
content-length: 74813
let rectangle = Rectangle(width: 42, height: 42)
let circle = Circle(radius: 42)
print(rectangle.accept(SquareShapeVisitor())) // 1764.0
print(circle.accept(SquareShapeVisitor())) // 5541.77
struct SquareShapeVisitor: ShapeVisitor {
func visit(_ rectangle: Rectangle) -> Float {
return rectangle.width * rectangle.height
}
func visit(_ circle: Circle) -> Float {
return circle.radius * circle.radius * Float.pi
}
}
protocol Shape {
func accept<V: ShapeVisitor>(_ visitor: V) -> V.Result
}
struct Rectangle: Shape {
let width: Float
let height: Float
func accept<V: ShapeVisitor>(_ visitor: V) -> V.Result {
return visitor.visit(self)
let square = rectangle.accept(SquareShapeVisitor())
let rectangle = Rectangle(width: 42, height: 42)
let circle = Circle(radius: 42)
let squareVisitor = SquareShapeVisitor()
rectangle.accept(squareVisitor)
print(squareVisitor.square) // 1764.0
circle.accept(squareVisitor)
print(squareVisitor.square) // 5541.77
protocol ShapeVisitor {
func visit(_ rectangle: Rectangle)
func visit(_ circle: Circle)
}
protocol Shape {
func accept(_ visitor: ShapeVisitor)
}
struct Rectangle: Shape {
protocol Shape {}
struct Rectangle: Shape {
let width: Float
let height: Float
}
struct Circle: Shape {
let radius: Float
}