Skip to content
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

Trainee Xcode Template #40

Open
wants to merge 1 commit into
base: master
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
1 change: 1 addition & 0 deletions Surf MVP Trainee Application.xctemplate/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please leave this file in place, it is here to provide folder structure in version control.
134 changes: 134 additions & 0 deletions Surf MVP Trainee Application.xctemplate/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
whitelist_rules:
- attributes
- class_delegate_protocol
- closing_brace
- closure_end_indentation
- closure_parameter_position
- closure_spacing
- collection_alignment
- colon
- comma
- conditional_returns_on_newline
- control_statement
- convenience_type
- custom_rules
- cyclomatic_complexity
- discouraged_optional_boolean
- duplicate_imports
- empty_count
- empty_parameters
- empty_parentheses_with_trailing_closure
- empty_string
- explicit_init
- file_length
- first_where
- force_cast
- force_try
- force_unwrapping
- function_parameter_count
- implicit_getter
- implicitly_unwrapped_optional
- inert_defer
- large_tuple
- last_where
- leading_whitespace
- legacy_cggeometry_functions
- legacy_constant
- legacy_constructor
- legacy_hashing
- legacy_nsgeometry_functions
- line_length
- literal_expression_end_indentation
- mark
- multiline_arguments
- multiline_literal_brackets
- notification_center_detachment
- opening_brace
- operator_usage_whitespace
- redundant_discardable_let
- redundant_optional_initialization
- redundant_nil_coalescing
- redundant_void_return
- return_arrow_whitespace
- shorthand_operator
- statement_position
- syntactic_sugar
- todo
- toggle_bool
- trailing_comma
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- unused_import
- unused_optional_binding
- unused_setter_value
- vertical_whitespace
- void_return
- weak_delegate

disabled_rules: # rule identifiers to exclude from running

opt_in_rules: # some rules are only opt-in

excluded: # paths to ignore during linting. Takes precedence over `included`.
- fastlane
- Pods
- .bundle

custom_rules:
image_name_initialization: # Disable UIImage init from name
included: ".*.swift"
name: "Image initialization"
regex: 'UIImage\(named:[^)]+\)'
message: "Use UIImage(assetName: ) instead"
severity: error

realm_in_ui:
included: "Screens/.*.swift|Flows/.*.swift|User Stories/.*.swift"
name: "Realm can be used only in services"
regex: "Realm"
message: "Realm can be used only in serivces"
severity: error

disclosure_of_view_details:
included: ".*ViewOutput.swift|.*ViewInput.swift"
name: "Details opening in View protocols"
regex: "cell|Cell|button|Button|Table|tableView"
message: "The disclosure of details the implementation should be avoided"
severity: error

view_protocol_error:
included: ".*ViewOutput.swift|.*ViewInput.swift"
name: "Property in view protocol"
regex: " var "
message: "View protocol should contains only methods"
severity: error

open_iboutlets:
included: ".*.swift"
name: "IBOutlet opening"
regex: "@IBOutlet ?(weak){0,1} var"
message: "IBOutlet should be private or fileprivate"
severity: error

open_ibaction:
included: ".*.swift"
name: "IBAction opening"
regex: "@IBAction func"
message: "IBAction should be private or fileprivate"
severity: error

mark_newlines:
included: ".*.swift"
name: "MARK newlines surrounding"
regex: '(([}{)\w \t]+\n{1}[ \t]*)(\/\/ MARK: - [\w ]*))|((\/\/ MARK: - [\w ]*)(\n{1}[ \t]*\w+))'
message: "Every MARK should be surrounded with 1 newline before and 1 after it"
severity: warning

line_length: 120

file_length:
warning: 500
error: 1200

reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit)
116 changes: 116 additions & 0 deletions Surf MVP Trainee Application.xctemplate/BaseParamsService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// BaseParamsService.swift
// TestProject
//
// Created by Vladislav Krupenko on 16.03.2020.
// Copyright © 2020 Fixique. All rights reserved.
//

import Foundation

enum BaseParamsService {

// MARK: - Keys

private enum Keys {
static let token = "token"
static let bundleId = "bundleId"
static let debug = "debug"
static let version = "version"
static let build = "build"
static let imageSize = "imageSize"
static let timeZone = "timeZone"
static let sig = "sig"
}

// MARK: - Properties

static var baseURL: URL? {
// TODO: Необходимо заменить на метод, который будет получать версию приложения
let currentVersion = "1.2.3"
return URL(string: "\(ServiceConstants.baseUrl)/v\(currentVersion)")
}

// MARK: - Internal Properties

static func getBaseParameters(parameters: [String: Any]) -> [String: Any] {
// TODO: Заменить на получение токена из другого сервиса
let token = ""

var extensionParameters = getExtensionParameters()
parameters.forEach { (k, v) in extensionParameters[k] = v}

let keys = Array(extensionParameters.keys)
let sortedKeys = keys.sorted { $0.caseInsensitiveCompare($1) == ComparisonResult.orderedAscending }
let objects = sortedKeys.map { extensionParameters[$0] }

var sortedParamsString = ""
for i in 0..<sortedKeys.count {
let object = objects[i]
var objectString: String?

switch object {
case let objectDictionary as [String: Any]:
if let jsonData = try? JSONSerialization.data(withJSONObject: objectDictionary, options: []) {
objectString = String(data: jsonData, encoding: String.Encoding.utf8)
}
case let objectArray as [Any]:
if let jsonData = try? JSONSerialization.data(withJSONObject: objectArray, options: []) {
objectString = String(data: jsonData, encoding: String.Encoding.utf8)
}
case let object as String:
objectString = object
default:
break
}

sortedParamsString = "\(sortedParamsString)\(sortedKeys[i])\(objectString ?? "")"
}

sortedParamsString = "\(token)\(sortedParamsString)\(ServiceConstants.privateKey)"
extensionParameters[Keys.sig] = sortedParamsString.md5()
return extensionParameters
}

}

// MARK: - Help Methods

private extension BaseParamsService {

static func getExtensionParameters() -> [String: Any] {
// TODO: Необходимо заменить на методы, которые будут возвращать значения из проекта
// Стоит спросить у ментора, какие текущие версии и билды поддерживаются сервером
// Также необходимо написать метод получения размера картинки
let version = "1.2.3"
let build = "123"
let imageSize = "1"

let extensionParamters: [String: Any] = [
// TODO: Необходимо получать токен от сервера, сохранять и получать его, если его нет, то стринга пустая
Keys.token: "",
Keys.bundleId: ServiceConstants.bundleId,
Keys.debug: "true",
Keys.version: version,
Keys.build: build,
Keys.imageSize: imageSize,
Keys.timeZone: getCurrentTimeZone()
]

return extensionParamters
}

static func getCurrentTimeZone() -> String {
let timeZoneOffset = Double(NSTimeZone.system.secondsFromGMT()) / 3600.0
var timeZoneString = String(format: "%ld", Int64(timeZoneOffset))

if timeZoneOffset > 0 {
timeZoneString = String(format: "+%ld", Int64(timeZoneOffset))
} else if timeZoneOffset < 0 {
timeZoneString = String(format: "%ld", Int64(timeZoneOffset))
}

return timeZoneString
}

}
6 changes: 6 additions & 0 deletions Surf MVP Trainee Application.xctemplate/Colors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// ___COPYRIGHT___
//

enum Colors {
}
Empty file.
17 changes: 17 additions & 0 deletions Surf MVP Trainee Application.xctemplate/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
source "https://rubygems.org"

# Ensure github repositories are fetched using HTTPS
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
puts(repo_name)
"https://github.com/#{repo_name}.git"
end if Gem::Version.new(Bundler::VERSION) < Gem::Version.new('2')

gem "fastlane", "~> 2.137.0"
gem 'cocoapods', "1.7.3"
gem 'synx', "~> 0.2.1"
gem 'xcpretty', "0.3.0"
gem 'generamba', github: 'surfstudio/Generamba', branch: 'develop', :ref => '91957270f4bc0092305ce6dbf016be5259720d33'

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

26 changes: 26 additions & 0 deletions Surf MVP Trainee Application.xctemplate/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
Loading