Skip to content
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
Binary file not shown.
2 changes: 2 additions & 0 deletions lesson05/5L_RaskinSergey/5L_RaskinSergey/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@ man.switch_engine(iflag:false)
man.fill_tunk(fill_volume: 500)
//печатаем что получилось
man.printDescription()


Binary file added lesson06/.DS_Store
Binary file not shown.
Binary file added lesson06/6L_RaskinSergey/.DS_Store
Binary file not shown.
131 changes: 131 additions & 0 deletions lesson06/6L_RaskinSergey/6LRaskinSergey.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//: A Cocoa based Playground to present user interface

import AppKit
import PlaygroundSupport

//
// main.swift
// 6L_RaskinSergey
//
// Created by raskin-sa on 04/12/2019.
// Copyright © 2019 raskin-sa. All rights reserved.
//

import Foundation

//протокол и расширение для красивой печати
protocol consolePrintable:CustomStringConvertible {
func printDescription()
}

extension consolePrintable{
func printDescription(){
print(description)
}
}

//протокол, содержащий стоимость для классов
protocol pricevalue {
var price: Double {get set}
var inputString: String {get set}
}

//делаем класс: строка со стоимостью
class ClassArrayString:pricevalue{

var price: Double
var inputString: String


init(inputString: String, price:Double){
// self.localstring = inputString
self.inputString = inputString
self.price = price
}
}

//наследник для работы с массивами Int
class ClassArrayInt:ClassArrayString{

init(inputInt:Int, price:Double){
super .init(inputString: String(inputInt), price: price)
}
}



//Реализовать свой тип коллекции «очередь» (queue) c использованием дженериков.

struct Queue<Element:pricevalue>: consolePrintable { // коллекция типа "очередь": Last In First Out
private var elements = [Element]()

mutating func push(_ item: Element) { // добавляем элемент в конец массив а
elements.append(item)
}
mutating func pop() -> Element? { // извлекаем первый элемент из массива
return elements.removeFirst()
}

//Добавить ему несколько методов высшего порядка, полезных для этой коллекции (пример: filter для массивов)

//функция, заданная через замыкание будет считать суммарную стоимость массива
var totalPrice : Double {
var price = 0.0
for element in elements {
price += element.price
}
return price
}// var totalPrice definition

//функция, заданная через замыкание будет выводить все элементы на печать
var description: String {
var lstr = "Элементы: "
for element in elements {
lstr += (" \(element.inputString)")
}
lstr += ". Суммарная стоимость массива: \(totalPrice)"
return lstr
}//var description definition

// *Добавить свой subscript, который будет возвращать nil в случае обращения к несуществующему индексу.

subscript(elements: Int) -> Bool? {

if elements > self.elements.count {
return nil
}
return true
}

}// struct definition


print("Массив строчных значений и его стоимость")
var tempArrayString = Queue<ClassArrayString>()
//var tempArrayInt = Queue<Int>()

tempArrayString.push(ClassArrayString(inputString: "Один", price: 1.0))
tempArrayString.push(ClassArrayString(inputString: "Семь", price: 12.0 ))
tempArrayString.printDescription()

print("Массив числовых значений и его стоимость")
var tempArrayInt = Queue<ClassArrayInt>()
tempArrayInt.push(ClassArrayInt(inputInt: 1, price: 1.0))
tempArrayInt.push(ClassArrayInt(inputInt: 7, price: 12.0 ))
tempArrayInt.printDescription()

print("проверяем сабскрипт c правильным индексом")
var correctindex = tempArrayString[2]
print("\(String(describing: correctindex))")

print("проверяем сабскрипт c неправильным индексом")
correctindex = tempArrayInt[3]
print("\(String(describing: correctindex))")

print("проверяем сабскрипт на пустом массиве")
tempArrayString.pop()
tempArrayString.pop()
correctindex = tempArrayString[1]
print("\(String(describing: correctindex))")


Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13115" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13115"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
<capability name="system font weights other than Regular or Bold" minToolsVersion="7.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner"/>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="c22-O7-iKe">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="LjM-KA-OXy">
<rect key="frame" x="153" y="116" width="175" height="39"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Hello World!" id="YLl-lC-HlH">
<font key="font" metaFont="systemUltraLight" size="32"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</customView>
</objects>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos'>
<timeline fileName='timeline.xctimeline'/>
</playground>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/raskin-sa/test/lesson06/6L_RaskinSergey/6LRaskinSergey.playground#CharacterRangeLen=5&amp;CharacterRangeLoc=1907&amp;EndingColumnNumber=18&amp;EndingLineNumber=74&amp;StartingColumnNumber=13&amp;StartingLineNumber=74&amp;Timestamp=597233867.43217"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/raskin-sa/test/lesson06/6L_RaskinSergey/6LRaskinSergey.playground#CharacterRangeLen=22&amp;CharacterRangeLoc=1574&amp;EndingColumnNumber=0&amp;EndingLineNumber=66&amp;StartingColumnNumber=16&amp;StartingLineNumber=65&amp;Timestamp=597233867.432273"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
</TimelineItems>
</Timeline>
Loading