WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit b4485ad

Browse files
authored
Merge pull request #12 from Cosmo/development
Development
2 parents cbc5cfd + 4fdba97 commit b4485ad

File tree

11 files changed

+283
-138
lines changed

11 files changed

+283
-138
lines changed

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ TinyConsoleController(rootViewController: MyMainViewController())
2323
### Actions
2424

2525
```swift
26-
// TinyConsole prints NSFormattedStrings and Strings
26+
// Print message
2727
TinyConsole.print("hello")
2828

29-
// print messages any color you want
29+
// Print messages any color you want
3030
TinyConsole.print("green text", color: UIColor.green)
3131

32-
// prints a red error message
32+
// Print a red error message
3333
TinyConsole.error("something went wrong")
3434

35+
// Print a marker for orientation
3536
TinyConsole.addMarker()
37+
38+
// Clear console
3639
TinyConsole.clear()
3740
```
3841

@@ -50,9 +53,9 @@ Instead of
5053

5154
```swift
5255
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
53-
self.window = UIWindow(frame: UIScreen.main.bounds)
54-
self.window?.rootViewController = MainViewController()
55-
self.window?.makeKeyAndVisible()
56+
window = UIWindow(frame: UIScreen.main.bounds)
57+
window?.rootViewController = MainViewController()
58+
window?.makeKeyAndVisible()
5659
return true
5760
}
5861
```
@@ -61,9 +64,9 @@ write
6164

6265
```swift
6366
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
64-
self.window = UIWindow(frame: UIScreen.main.bounds)
65-
self.window?.rootViewController = TinyConsoleController(rootViewController: MainViewController())
66-
self.window?.makeKeyAndVisible()
67+
window = UIWindow(frame: UIScreen.main.bounds)
68+
window?.rootViewController = TinyConsoleController(rootViewController: MainViewController())
69+
window?.makeKeyAndVisible()
6770
return true
6871
}
6972
```
@@ -74,6 +77,12 @@ or checkout the example project included in this repository.
7477

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

80+
## Requirements
81+
82+
* Xcode 8
83+
* Swift 3
84+
* iOS 8 or greater
85+
7786
## Installation
7887

7988
### [Carthage](https://github.com/Carthage/Carthage)

TinyConsole-Example/AppDelegate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

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

1919
let viewController = UINavigationController(rootViewController: MainViewController())
2020
viewController.title = "Main"
@@ -25,8 +25,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2525
viewController
2626
]
2727

28-
self.window?.rootViewController = TinyConsoleController(rootViewController: tabBarController)
29-
self.window?.makeKeyAndVisible()
28+
window?.rootViewController = TinyConsoleController(rootViewController: tabBarController)
29+
window?.makeKeyAndVisible()
3030

3131
return true
3232
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// DataSource.swift
3+
// TinyConsole
4+
//
5+
// Created by Devran Uenal on 11.12.16.
6+
//
7+
//
8+
9+
import UIKit
10+
11+
class MainTableViewDataSource: NSObject, UITableViewDataSource {
12+
func registerCellsForTableView(_ tableView: UITableView) {
13+
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "default")
14+
}
15+
16+
func numberOfSections(in tableView: UITableView) -> Int {
17+
return 1
18+
}
19+
20+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
21+
return 30
22+
}
23+
24+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
25+
let cell = tableView.dequeueReusableCell(withIdentifier: "default", for: indexPath)
26+
cell.textLabel?.text = "Row \(indexPath.row)"
27+
return cell
28+
}
29+
}

TinyConsole-Example/Delegate.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Delegate.swift
3+
// TinyConsole
4+
//
5+
// Created by Devran Uenal on 11.12.16.
6+
//
7+
//
8+
9+
import UIKit
10+
import TinyConsole
11+
12+
class MainTableViewDelegate: NSObject, UITableViewDelegate {
13+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
14+
TinyConsole.print("Tapped on \(indexPath.row)")
15+
}
16+
}

TinyConsole-Example/MainViewController.swift

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,55 @@ import UIKit
1010
import TinyConsole
1111

1212
class MainViewController: UITableViewController {
13-
override func viewDidLoad() {
14-
super.viewDidLoad()
15-
self.view.backgroundColor = UIColor.white
16-
17-
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "default")
18-
19-
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Add Log", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addLog))
20-
self.navigationItem.rightBarButtonItems = [
21-
UIBarButtonItem(title: "Add Marker", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addMarker)),
22-
UIBarButtonItem(title: "Clear", style: UIBarButtonItemStyle.plain, target: self, action: #selector(clear)),
23-
]
24-
}
13+
var tableViewDelegate: UITableViewDelegate
14+
var tableViewDataSource: UITableViewDataSource
2515

26-
override func numberOfSections(in tableView: UITableView) -> Int {
27-
return 1
16+
init() {
17+
tableViewDelegate = MainTableViewDelegate()
18+
tableViewDataSource = MainTableViewDataSource()
19+
super.init(style: UITableViewStyle.plain)
2820
}
2921

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

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

37-
cell.textLabel?.text = "Row \(indexPath.row)"
31+
super.viewDidLoad()
32+
view.backgroundColor = UIColor.white
3833

39-
return cell
34+
setupNavigationItems()
4035
}
41-
42-
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
43-
TinyConsole.print("Tapped on \(indexPath.row)")
36+
37+
override func viewDidAppear(_ animated: Bool) {
38+
super.viewDidAppear(animated)
39+
40+
TinyConsole.print("Welcome to TinyConsole")
41+
TinyConsole.addMarker()
42+
TinyConsole.print("NOW", color: UIColor.red)
43+
TinyConsole.print("IN", color: UIColor.green)
44+
TinyConsole.print("COLOR", color: UIColor.blue)
45+
TinyConsole.addMarker()
4446
}
4547

48+
func setupNavigationItems() {
49+
navigationItem.leftBarButtonItems = [
50+
UIBarButtonItem(title: "Add Log", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addLog))
51+
]
52+
navigationItem.rightBarButtonItems = [
53+
UIBarButtonItem( title: "Add Marker", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addMarker)),
54+
UIBarButtonItem( title: "Clear", style: UIBarButtonItemStyle.plain, target: self, action: #selector(clear)),
55+
]
56+
}
57+
}
58+
59+
extension MainViewController {
4660
func addLog() {
47-
TinyConsole.print("hello world")
61+
TinyConsole.print("Hello World")
4862
}
4963

5064
func clear() {
@@ -55,4 +69,3 @@ class MainViewController: UITableViewController {
5569
TinyConsole.addMarker()
5670
}
5771
}
58-

TinyConsole.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'TinyConsole'
3-
s.version = '1.2.1'
3+
s.version = '1.3.1'
44
s.summary = 'A tiny log console to display information while using your iOS app. Written in Swift 3.'
55

66
s.description = <<-DESC

TinyConsole.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

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

4648
/* Begin PBXFileReference section */
49+
450284DD1DFD878C00922381 /* DataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataSource.swift; sourceTree = "<group>"; };
50+
450284DF1DFD87BA00922381 /* Delegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Delegate.swift; sourceTree = "<group>"; };
4751
4585FDCB1DEC54B800DDF5EB /* TinyConsole.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TinyConsole.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4852
4585FDD51DEC54D300DDF5EB /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4953
4585FDD61DEC54D300DDF5EB /* TinyConsole.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TinyConsole.h; sourceTree = "<group>"; };
@@ -120,6 +124,8 @@
120124
children = (
121125
4585FDE51DEC58BB00DDF5EB /* AppDelegate.swift */,
122126
4585FDE71DEC58BB00DDF5EB /* MainViewController.swift */,
127+
450284DD1DFD878C00922381 /* DataSource.swift */,
128+
450284DF1DFD87BA00922381 /* Delegate.swift */,
123129
4585FDEC1DEC58BB00DDF5EB /* Assets.xcassets */,
124130
4585FDEE1DEC58BB00DDF5EB /* LaunchScreen.storyboard */,
125131
4585FDF11DEC58BB00DDF5EB /* Info.plist */,
@@ -251,6 +257,8 @@
251257
isa = PBXSourcesBuildPhase;
252258
buildActionMask = 2147483647;
253259
files = (
260+
450284E01DFD87BA00922381 /* Delegate.swift in Sources */,
261+
450284DE1DFD878C00922381 /* DataSource.swift in Sources */,
254262
4585FDE81DEC58BB00DDF5EB /* MainViewController.swift in Sources */,
255263
4585FDE61DEC58BB00DDF5EB /* AppDelegate.swift in Sources */,
256264
);

TinyConsole/Supporting Files/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>1.3.1</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

TinyConsole/TinyConsole.swift

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ open class TinyConsole {
1212
public static var shared = TinyConsole()
1313
var textView: UITextView?
1414

15-
public static var textAppearance = [NSFontAttributeName : UIFont(name: "Menlo", size: 12.0)!, NSForegroundColorAttributeName : UIColor.white]
15+
public static var textAppearance = [
16+
NSFontAttributeName: UIFont(name: "Menlo", size: 12.0)!,
17+
NSForegroundColorAttributeName: UIColor.white]
1618

1719
private init() {
1820
}
@@ -25,7 +27,7 @@ open class TinyConsole {
2527
}()
2628

2729
func currentTimeStamp() -> String {
28-
return self.dateFormatter.string(from: Date())
30+
return dateFormatter.string(from: Date())
2931
}
3032

3133
public static func scrollToBottom() {
@@ -36,7 +38,7 @@ open class TinyConsole {
3638
}
3739
}
3840

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

@@ -47,21 +49,21 @@ open class TinyConsole {
4749
TinyConsole.print(formattedText, global: global)
4850
}
4951

50-
public static func print(_ text: NSAttributedString, global : Bool = true) {
52+
public static func print(_ text: NSAttributedString, global: Bool = true) {
5153
if let textView = shared.textView {
52-
let timeStamped = NSMutableAttributedString(string: shared.currentTimeStamp() + " ")
53-
let range = NSRange(location: 0, length: timeStamped.length)
54+
DispatchQueue.main.async {
55+
let timeStamped = NSMutableAttributedString(string: shared.currentTimeStamp() + " ")
56+
let range = NSRange(location: 0, length: timeStamped.length)
5457

55-
// set standard text appearance for time-stamp
56-
timeStamped.addAttributes(TinyConsole.textAppearance, range: range)
57-
58-
timeStamped.append(text)
59-
timeStamped.append(NSAttributedString(string :"\n"))
58+
// set standard text appearance for time-stamp
59+
timeStamped.addAttributes(TinyConsole.textAppearance, range: range)
6060

61-
let newText = NSMutableAttributedString(attributedString: textView.attributedText)
62-
newText.append(timeStamped)
61+
timeStamped.append(text)
62+
timeStamped.append(NSAttributedString(string: "\n"))
63+
64+
let newText = NSMutableAttributedString(attributedString: textView.attributedText)
65+
newText.append(timeStamped)
6366

64-
DispatchQueue.main.async {
6567
textView.attributedText = newText
6668
TinyConsole.scrollToBottom()
6769
}

0 commit comments

Comments
 (0)