diff --git a/lesson05/5L_RaskinSergey/5L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate b/lesson05/5L_RaskinSergey/5L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate index b3eeff6..e3b44a1 100644 Binary files a/lesson05/5L_RaskinSergey/5L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate and b/lesson05/5L_RaskinSergey/5L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/lesson05/5L_RaskinSergey/5L_RaskinSergey/main.swift b/lesson05/5L_RaskinSergey/5L_RaskinSergey/main.swift index 207c327..993c789 100644 --- a/lesson05/5L_RaskinSergey/5L_RaskinSergey/main.swift +++ b/lesson05/5L_RaskinSergey/5L_RaskinSergey/main.swift @@ -164,3 +164,5 @@ man.switch_engine(iflag:false) man.fill_tunk(fill_volume: 500) //печатаем что получилось man.printDescription() + + diff --git a/lesson06/.DS_Store b/lesson06/.DS_Store new file mode 100644 index 0000000..9503165 Binary files /dev/null and b/lesson06/.DS_Store differ diff --git a/lesson06/6L_RaskinSergey/.DS_Store b/lesson06/6L_RaskinSergey/.DS_Store new file mode 100644 index 0000000..e07b12d Binary files /dev/null and b/lesson06/6L_RaskinSergey/.DS_Store differ diff --git a/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/Contents.swift b/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/Contents.swift new file mode 100644 index 0000000..3f011b7 --- /dev/null +++ b/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/Contents.swift @@ -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: 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() +//var tempArrayInt = Queue() + +tempArrayString.push(ClassArrayString(inputString: "Один", price: 1.0)) +tempArrayString.push(ClassArrayString(inputString: "Семь", price: 12.0 )) +tempArrayString.printDescription() + +print("Массив числовых значений и его стоимость") +var tempArrayInt = Queue() +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))") + + diff --git a/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/Resources/MyView.xib b/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/Resources/MyView.xib new file mode 100644 index 0000000..61f90c0 --- /dev/null +++ b/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/Resources/MyView.xib @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/contents.xcplayground b/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/contents.xcplayground new file mode 100644 index 0000000..63b6dd8 --- /dev/null +++ b/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/timeline.xctimeline b/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/timeline.xctimeline new file mode 100644 index 0000000..cbeed4a --- /dev/null +++ b/lesson06/6L_RaskinSergey/6LRaskinSergey.playground/timeline.xctimeline @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.pbxproj b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.pbxproj new file mode 100644 index 0000000..c2a8752 --- /dev/null +++ b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.pbxproj @@ -0,0 +1,289 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 91A97D8B2397C15B00015775 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91A97D8A2397C15B00015775 /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 91A97D852397C15B00015775 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 91A97D872397C15B00015775 /* 6L_RaskinSergey */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = 6L_RaskinSergey; sourceTree = BUILT_PRODUCTS_DIR; }; + 91A97D8A2397C15B00015775 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 91A97D842397C15B00015775 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 91A97D7E2397C15B00015775 = { + isa = PBXGroup; + children = ( + 91A97D892397C15B00015775 /* 6L_RaskinSergey */, + 91A97D882397C15B00015775 /* Products */, + ); + sourceTree = ""; + }; + 91A97D882397C15B00015775 /* Products */ = { + isa = PBXGroup; + children = ( + 91A97D872397C15B00015775 /* 6L_RaskinSergey */, + ); + name = Products; + sourceTree = ""; + }; + 91A97D892397C15B00015775 /* 6L_RaskinSergey */ = { + isa = PBXGroup; + children = ( + 91A97D8A2397C15B00015775 /* main.swift */, + ); + path = 6L_RaskinSergey; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 91A97D862397C15B00015775 /* 6L_RaskinSergey */ = { + isa = PBXNativeTarget; + buildConfigurationList = 91A97D8E2397C15B00015775 /* Build configuration list for PBXNativeTarget "6L_RaskinSergey" */; + buildPhases = ( + 91A97D832397C15B00015775 /* Sources */, + 91A97D842397C15B00015775 /* Frameworks */, + 91A97D852397C15B00015775 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = 6L_RaskinSergey; + productName = 6L_RaskinSergey; + productReference = 91A97D872397C15B00015775 /* 6L_RaskinSergey */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 91A97D7F2397C15B00015775 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1120; + LastUpgradeCheck = 1120; + ORGANIZATIONNAME = "raskin-sa"; + TargetAttributes = { + 91A97D862397C15B00015775 = { + CreatedOnToolsVersion = 11.2.1; + }; + }; + }; + buildConfigurationList = 91A97D822397C15B00015775 /* Build configuration list for PBXProject "6L_RaskinSergey" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 91A97D7E2397C15B00015775; + productRefGroup = 91A97D882397C15B00015775 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 91A97D862397C15B00015775 /* 6L_RaskinSergey */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 91A97D832397C15B00015775 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91A97D8B2397C15B00015775 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 91A97D8C2397C15B00015775 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + 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; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 91A97D8D2397C15B00015775 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + 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; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 91A97D8F2397C15B00015775 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 5C3KKHP5ML; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 91A97D902397C15B00015775 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 5C3KKHP5ML; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 91A97D822397C15B00015775 /* Build configuration list for PBXProject "6L_RaskinSergey" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91A97D8C2397C15B00015775 /* Debug */, + 91A97D8D2397C15B00015775 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 91A97D8E2397C15B00015775 /* Build configuration list for PBXNativeTarget "6L_RaskinSergey" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91A97D8F2397C15B00015775 /* Debug */, + 91A97D902397C15B00015775 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 91A97D7F2397C15B00015775 /* Project object */; +} diff --git a/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..53aa30c --- /dev/null +++ b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..75f6125 Binary files /dev/null and b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..0917599 --- /dev/null +++ b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,6 @@ + + + diff --git a/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..6c0878e --- /dev/null +++ b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + 6L_RaskinSergey.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/lesson06/6L_RaskinSergey/6L_RaskinSergey/main.swift b/lesson06/6L_RaskinSergey/6L_RaskinSergey/main.swift new file mode 100644 index 0000000..492c979 --- /dev/null +++ b/lesson06/6L_RaskinSergey/6L_RaskinSergey/main.swift @@ -0,0 +1,124 @@ +// +// 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: 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() +//var tempArrayInt = Queue() + +tempArrayString.push(ClassArrayString(inputString: "Один", price: 1.0)) +tempArrayString.push(ClassArrayString(inputString: "Семь", price: 12.0 )) +tempArrayString.printDescription() + +print("Массив числовых значений и его стоимость") +var tempArrayInt = Queue() +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))")