Skip to content

Commit

Permalink
Merge pull request #12 from Cosmo/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Cosmo committed Dec 11, 2016
2 parents cbc5cfd + 4fdba97 commit b4485ad
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 138 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ TinyConsoleController(rootViewController: MyMainViewController())
### Actions

```swift
// TinyConsole prints NSFormattedStrings and Strings
// Print message
TinyConsole.print("hello")

// print messages any color you want
// Print messages any color you want
TinyConsole.print("green text", color: UIColor.green)

// prints a red error message
// Print a red error message
TinyConsole.error("something went wrong")

// Print a marker for orientation
TinyConsole.addMarker()

// Clear console
TinyConsole.clear()
```

Expand All @@ -50,9 +53,9 @@ Instead of

```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = MainViewController()
self.window?.makeKeyAndVisible()
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = MainViewController()
window?.makeKeyAndVisible()
return true
}
```
Expand All @@ -61,9 +64,9 @@ write

```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = TinyConsoleController(rootViewController: MainViewController())
self.window?.makeKeyAndVisible()
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = TinyConsoleController(rootViewController: MainViewController())
window?.makeKeyAndVisible()
return true
}
```
Expand All @@ -74,6 +77,12 @@ or checkout the example project included in this repository.

<img src="https://raw.githubusercontent.com/Cosmo/TinyConsole/master/TinyConsole-Demo.gif" alt=" text" width="25%" />

## Requirements

* Xcode 8
* Swift 3
* iOS 8 or greater

## Installation

### [Carthage](https://github.com/Carthage/Carthage)
Expand Down
6 changes: 3 additions & 3 deletions TinyConsole-Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
window = UIWindow(frame: UIScreen.main.bounds)

let viewController = UINavigationController(rootViewController: MainViewController())
viewController.title = "Main"
Expand All @@ -25,8 +25,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
viewController
]

self.window?.rootViewController = TinyConsoleController(rootViewController: tabBarController)
self.window?.makeKeyAndVisible()
window?.rootViewController = TinyConsoleController(rootViewController: tabBarController)
window?.makeKeyAndVisible()

return true
}
Expand Down
29 changes: 29 additions & 0 deletions TinyConsole-Example/DataSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// DataSource.swift
// TinyConsole
//
// Created by Devran Uenal on 11.12.16.
//
//

import UIKit

class MainTableViewDataSource: NSObject, UITableViewDataSource {
func registerCellsForTableView(_ tableView: UITableView) {
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "default")
}

func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 30
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "default", for: indexPath)
cell.textLabel?.text = "Row \(indexPath.row)"
return cell
}
}
16 changes: 16 additions & 0 deletions TinyConsole-Example/Delegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Delegate.swift
// TinyConsole
//
// Created by Devran Uenal on 11.12.16.
//
//

import UIKit
import TinyConsole

class MainTableViewDelegate: NSObject, UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
TinyConsole.print("Tapped on \(indexPath.row)")
}
}
63 changes: 38 additions & 25 deletions TinyConsole-Example/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,55 @@ import UIKit
import TinyConsole

class MainViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.white

self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "default")

self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Add Log", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addLog))
self.navigationItem.rightBarButtonItems = [
UIBarButtonItem(title: "Add Marker", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addMarker)),
UIBarButtonItem(title: "Clear", style: UIBarButtonItemStyle.plain, target: self, action: #selector(clear)),
]
}
var tableViewDelegate: UITableViewDelegate
var tableViewDataSource: UITableViewDataSource

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
init() {
tableViewDelegate = MainTableViewDelegate()
tableViewDataSource = MainTableViewDataSource()
super.init(style: UITableViewStyle.plain)
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 30
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "default", for: indexPath)
override func viewDidLoad() {
(tableViewDataSource as? MainTableViewDataSource)?.registerCellsForTableView(self.tableView)
tableView.delegate = tableViewDelegate
tableView.dataSource = tableViewDataSource

cell.textLabel?.text = "Row \(indexPath.row)"
super.viewDidLoad()
view.backgroundColor = UIColor.white

return cell
setupNavigationItems()
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
TinyConsole.print("Tapped on \(indexPath.row)")

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

TinyConsole.print("Welcome to TinyConsole")
TinyConsole.addMarker()
TinyConsole.print("NOW", color: UIColor.red)
TinyConsole.print("IN", color: UIColor.green)
TinyConsole.print("COLOR", color: UIColor.blue)
TinyConsole.addMarker()
}

func setupNavigationItems() {
navigationItem.leftBarButtonItems = [
UIBarButtonItem(title: "Add Log", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addLog))
]
navigationItem.rightBarButtonItems = [
UIBarButtonItem( title: "Add Marker", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addMarker)),
UIBarButtonItem( title: "Clear", style: UIBarButtonItemStyle.plain, target: self, action: #selector(clear)),
]
}
}

extension MainViewController {
func addLog() {
TinyConsole.print("hello world")
TinyConsole.print("Hello World")
}

func clear() {
Expand All @@ -55,4 +69,3 @@ class MainViewController: UITableViewController {
TinyConsole.addMarker()
}
}

2 changes: 1 addition & 1 deletion TinyConsole.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TinyConsole'
s.version = '1.2.1'
s.version = '1.3.1'
s.summary = 'A tiny log console to display information while using your iOS app. Written in Swift 3.'

s.description = <<-DESC
Expand Down
8 changes: 8 additions & 0 deletions TinyConsole.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
450284DE1DFD878C00922381 /* DataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 450284DD1DFD878C00922381 /* DataSource.swift */; };
450284E01DFD87BA00922381 /* Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 450284DF1DFD87BA00922381 /* Delegate.swift */; };
457B894F1DF4DB74001DD49C /* TinyConsole.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4585FDCB1DEC54B800DDF5EB /* TinyConsole.framework */; };
457B89501DF4DB74001DD49C /* TinyConsole.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4585FDCB1DEC54B800DDF5EB /* TinyConsole.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4585FDD81DEC54D300DDF5EB /* TinyConsole.h in Headers */ = {isa = PBXBuildFile; fileRef = 4585FDD61DEC54D300DDF5EB /* TinyConsole.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -44,6 +46,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
450284DD1DFD878C00922381 /* DataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataSource.swift; sourceTree = "<group>"; };
450284DF1DFD87BA00922381 /* Delegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Delegate.swift; sourceTree = "<group>"; };
4585FDCB1DEC54B800DDF5EB /* TinyConsole.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TinyConsole.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4585FDD51DEC54D300DDF5EB /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4585FDD61DEC54D300DDF5EB /* TinyConsole.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TinyConsole.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -120,6 +124,8 @@
children = (
4585FDE51DEC58BB00DDF5EB /* AppDelegate.swift */,
4585FDE71DEC58BB00DDF5EB /* MainViewController.swift */,
450284DD1DFD878C00922381 /* DataSource.swift */,
450284DF1DFD87BA00922381 /* Delegate.swift */,
4585FDEC1DEC58BB00DDF5EB /* Assets.xcassets */,
4585FDEE1DEC58BB00DDF5EB /* LaunchScreen.storyboard */,
4585FDF11DEC58BB00DDF5EB /* Info.plist */,
Expand Down Expand Up @@ -251,6 +257,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
450284E01DFD87BA00922381 /* Delegate.swift in Sources */,
450284DE1DFD878C00922381 /* DataSource.swift in Sources */,
4585FDE81DEC58BB00DDF5EB /* MainViewController.swift in Sources */,
4585FDE61DEC58BB00DDF5EB /* AppDelegate.swift in Sources */,
);
Expand Down
2 changes: 1 addition & 1 deletion TinyConsole/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.3.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
30 changes: 16 additions & 14 deletions TinyConsole/TinyConsole.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ open class TinyConsole {
public static var shared = TinyConsole()
var textView: UITextView?

public static var textAppearance = [NSFontAttributeName : UIFont(name: "Menlo", size: 12.0)!, NSForegroundColorAttributeName : UIColor.white]
public static var textAppearance = [
NSFontAttributeName: UIFont(name: "Menlo", size: 12.0)!,
NSForegroundColorAttributeName: UIColor.white]

private init() {
}
Expand All @@ -25,7 +27,7 @@ open class TinyConsole {
}()

func currentTimeStamp() -> String {
return self.dateFormatter.string(from: Date())
return dateFormatter.string(from: Date())
}

public static func scrollToBottom() {
Expand All @@ -36,7 +38,7 @@ open class TinyConsole {
}
}

public static func print(_ text: String, global: Bool = true, color : UIColor = UIColor.white) {
public static func print(_ text: String, color: UIColor = UIColor.white, global: Bool = true) {
let formattedText = NSMutableAttributedString(string: text)
let range = NSRange(location: 0, length: formattedText.length)

Expand All @@ -47,21 +49,21 @@ open class TinyConsole {
TinyConsole.print(formattedText, global: global)
}

public static func print(_ text: NSAttributedString, global : Bool = true) {
public static func print(_ text: NSAttributedString, global: Bool = true) {
if let textView = shared.textView {
let timeStamped = NSMutableAttributedString(string: shared.currentTimeStamp() + " ")
let range = NSRange(location: 0, length: timeStamped.length)
DispatchQueue.main.async {
let timeStamped = NSMutableAttributedString(string: shared.currentTimeStamp() + " ")
let range = NSRange(location: 0, length: timeStamped.length)

// set standard text appearance for time-stamp
timeStamped.addAttributes(TinyConsole.textAppearance, range: range)

timeStamped.append(text)
timeStamped.append(NSAttributedString(string :"\n"))
// set standard text appearance for time-stamp
timeStamped.addAttributes(TinyConsole.textAppearance, range: range)

let newText = NSMutableAttributedString(attributedString: textView.attributedText)
newText.append(timeStamped)
timeStamped.append(text)
timeStamped.append(NSAttributedString(string: "\n"))

let newText = NSMutableAttributedString(attributedString: textView.attributedText)
newText.append(timeStamped)

DispatchQueue.main.async {
textView.attributedText = newText
TinyConsole.scrollToBottom()
}
Expand Down
Loading

0 comments on commit b4485ad

Please sign in to comment.