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

Swift Package Support #2

Open
wants to merge 2 commits 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
11 changes: 11 additions & 0 deletions .build/workspace-state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"object" : {
"artifacts" : [

],
"dependencies" : [

]
},
"version" : 5
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ profile
DerivedData
*.hmap
*.ipa
.swiftpm/

# Bundler
.bundle
Expand Down
2 changes: 2 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--exclude Pods,Generated
--swiftversion 5.0
102 changes: 102 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
excluded:
- DerivedData
- SourcePackages

disabled_rules:
- discarded_notification_center_observer
- notification_center_detachment
- orphaned_doc_comment
- todo
- unused_capture_list
- trailing_comma
- opening_brace

opt_in_rules:
- array_init
- attributes
- closure_end_indentation
- closure_spacing
- collection_alignment
- colon # promote to error
- convenience_type
- discouraged_object_literal
- empty_collection_literal
- empty_count
- empty_string
- enum_case_associated_values_count
- fatal_error_message
- first_where
- force_unwrapping
- last_where
- legacy_random
- literal_expression_end_indentation
- multiline_arguments
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
- multiline_parameters_brackets
- operator_usage_whitespace
- overridden_super_call
- pattern_matching_keywords
- prefer_self_type_over_type_of_self
- redundant_nil_coalescing
- redundant_type_annotation
- toggle_bool
- trailing_closure
- unneeded_parentheses_in_closure_argument
- unused_import
- yoda_condition


custom_rules:
array_constructor:
name: "Array/Dictionary initializer"
regex: '[let,var] .+ = (\[.+\]\(\))'
capture_group: 1
message: "Use explicit type annotation when initializing empty arrays and dictionaries"
severity: warning


attributes:
always_on_same_line:
- "@IBSegueAction"
- "@IBAction"
- "@NSManaged"
- "@objc"

force_cast: warning
force_try: warning
function_body_length:
warning: 60

legacy_hashing: error

identifier_name:
excluded:
- i
- id
- x
- y
- z

indentation_width:
indentation_width: 4

line_length:
ignores_urls: true
ignores_function_declarations: true
ignores_comments: true

multiline_arguments:
first_argument_location: next_line
only_enforce_after_first_closure_on_first_line: true

private_over_fileprivate:
validate_extensions: true

trailing_whitespace:
ignores_empty_lines: true
ignores_comments: true

vertical_whitespace:
max_empty_lines: 2
12 changes: 5 additions & 7 deletions Example/Tests/Tests.swift
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import mtpThemeManager
import UIKit
import XCTest
import mtpThemeManager

class Tests: XCTestCase {

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}

func testExample() {
// This is an example of a functional test case.
XCTAssert(true, "Pass")
}

func testPerformanceExample() {
// This is an example of a performance test case.
self.measure() {
measure {
// Put the code you want to measure the time of here.
}
}

}
9 changes: 3 additions & 6 deletions Example/mtpThemeManager/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
// Copyright (c) 2017 mostafa.taghipour@ymail.com. All rights reserved.
//

import UIKit
import mtpThemeManager
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
ThemeManager.shared.setTheme(dayNight: RedTheme())
return true
}

}

14 changes: 5 additions & 9 deletions Example/mtpThemeManager/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

import UIKit


extension UIPickerView {
private struct associationKey{
private struct associationKey {
static var selectorColorAssociationKey: UInt8 = 0
}



@IBInspectable dynamic var selectorColor: UIColor? {
get {
return objc_getAssociatedObject(self, &associationKey.selectorColorAssociationKey) as? UIColor
Expand All @@ -24,16 +22,14 @@ extension UIPickerView {
objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
}
}
open override func didAddSubview(_ subview: UIView) {

override open func didAddSubview(_ subview: UIView) {
super.didAddSubview(subview)

if let color = selectorColor {
if subview.bounds.height < 1.0 {
subview.backgroundColor = color
}
}
}


}
76 changes: 33 additions & 43 deletions Example/mtpThemeManager/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,38 @@
// Copyright © 2017 CocoaPods. All rights reserved.
//

import UIKit
import mtpThemeManager
import UIKit

class SettingsViewController: UIViewController {

@IBOutlet weak var themePicker: UIPickerView!
@IBOutlet weak var nightPicker: UIPickerView!

let themeManager=ThemeManager.shared
var allThemes:[Theme]!

@IBOutlet var themePicker: UIPickerView!
@IBOutlet var nightPicker: UIPickerView!

let themeManager = ThemeManager.shared
var allThemes: [Theme]!

override func viewDidLoad() {
super.viewDidLoad()


themePicker.dataSource=self
themePicker.delegate=self
themePicker.dataSource = self
themePicker.delegate = self
themePicker.selectorColor = secondaryTextColor
allThemes=themeManager.availableThemes
if let currentTheme=themeManager.currentTheme , let selectedValue=allThemes.firstIndex(where: {$0.id==currentTheme.id}){

allThemes = themeManager.availableThemes
if let currentTheme = themeManager.currentTheme, let selectedValue = allThemes.firstIndex(where: { $0.id == currentTheme.id }) {
themePicker.selectRow(selectedValue, inComponent: 0, animated: false)
}
nightPicker.dataSource=self
nightPicker.delegate=self

nightPicker.dataSource = self
nightPicker.delegate = self
nightPicker.selectorColor = secondaryTextColor


if let selectedValue=NightModeStatus.all.firstIndex(of: themeManager.nightModeStatus ){

if let selectedValue = NightModeStatus.all.firstIndex(of: themeManager.nightModeStatus) {
nightPicker.selectRow(selectedValue, inComponent: 0, animated: false)
}
}


func reloadAllViewControllers(){

func reloadAllViewControllers() {
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let navigationController = mainStoryboard.instantiateViewController(withIdentifier: "mainNavigationController") as! UINavigationController
let settingVC = mainStoryboard.instantiateViewController(withIdentifier: "settingVC")
Expand All @@ -50,37 +46,31 @@ class SettingsViewController: UIViewController {
}
}


extension SettingsViewController:UIPickerViewDelegate,UIPickerViewDataSource{
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
extension SettingsViewController: UIPickerViewDelegate, UIPickerViewDataSource {
func numberOfComponents(in _: UIPickerView) -> Int {
return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {


func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent _: Int) -> Int {
return pickerView === themePicker ? allThemes.count : NightModeStatus.all.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent _: Int) -> String? {
return pickerView === themePicker ? allThemes[row].displayName : "\(NightModeStatus.all[row])"
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if (pickerView === themePicker){

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent _: Int) {
if pickerView === themePicker {
themeManager.setTheme(dayNight: allThemes[row] as! AppTheme)
}
else{
} else {
themeManager.nightModeStatus = NightModeStatus.all[row]
}
reloadAllViewControllers()
}
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {

func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent _: Int) -> NSAttributedString? {
let titleData = pickerView === themePicker ? allThemes[row].displayName : "\(NightModeStatus.all[row])"
let myTitle = NSAttributedString(string: titleData, attributes: [NSAttributedString.Key.foregroundColor:themeManager.primaryTextColor!])
let myTitle = NSAttributedString(string: titleData, attributes: [NSAttributedString.Key.foregroundColor: themeManager.primaryTextColor!])
return myTitle
}
}



29 changes: 14 additions & 15 deletions Example/mtpThemeManager/Themes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,39 @@
// Copyright © 2017 CocoaPods. All rights reserved.
//

import UIKit
import mtpThemeManager
import UIKit

protocol AppTheme:DayNightTheme {}
protocol AppTheme: DayNightTheme {}

class RedTheme:AppTheme {
required init() {}
var id: Int=1
var displayName: String="Red"
class RedTheme: AppTheme {
required init() {}
var id: Int = 1
var displayName: String = "Red"
var tintColor: UIColor = .red

}

class BlueTheme:AppTheme {
required init() {}
var id: Int=2
var displayName: String="Blue"
class BlueTheme: AppTheme {
required init() {}
var id: Int = 2
var displayName: String = "Blue"
var tintColor: UIColor = .blue
}

extension AppTheme{
extension AppTheme {
var secondaryTextColor: UIColor {
return UIColor.gray.withAlphaComponent(0.8)
}

var secondaryTextColorNight: UIColor {
return UIColor.gray.withAlphaComponent(0.9)
}
}

var currentTheme : AppTheme {
var currentTheme: AppTheme {
return ThemeManager.shared.currentTheme as! AppTheme
}

var secondaryTextColor:UIColor{
var secondaryTextColor: UIColor {
return ThemeManager.shared.isItNight ? currentTheme.secondaryTextColorNight : currentTheme.secondaryTextColor
}
Loading