Skip to content

Commit 4049dbc

Browse files
committed
Renamed files.
1 parent 4e14b71 commit 4049dbc

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

SwiftyJSONAccelerator.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
9362F8661BD07DBA0001372E /* JSONHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9362F8651BD07DBA0001372E /* JSONHelperTests.swift */; settings = {ASSET_TAGS = (); }; };
1212
93CDE7721BD1A00B00B5B234 /* SJTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93CDE7711BD1A00B00B5B234 /* SJTextView.swift */; settings = {ASSET_TAGS = (); }; };
1313
93F174431BD0707D007E7DFC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F174421BD0707D007E7DFC /* AppDelegate.swift */; };
14-
93F174451BD0707D007E7DFC /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F174441BD0707D007E7DFC /* ViewController.swift */; };
14+
93F174451BD0707D007E7DFC /* SJEditorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F174441BD0707D007E7DFC /* SJEditorViewController.swift */; };
1515
93F174471BD0707D007E7DFC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 93F174461BD0707D007E7DFC /* Assets.xcassets */; };
1616
93F1744A1BD0707D007E7DFC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 93F174481BD0707D007E7DFC /* Main.storyboard */; };
1717
93F174551BD0707D007E7DFC /* SwiftyJSONAcceleratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F174541BD0707D007E7DFC /* SwiftyJSONAcceleratorTests.swift */; };
@@ -34,7 +34,7 @@
3434
93CDE7711BD1A00B00B5B234 /* SJTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SJTextView.swift; sourceTree = "<group>"; };
3535
93F1743F1BD0707D007E7DFC /* SwiftyJSONAccelerator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftyJSONAccelerator.app; sourceTree = BUILT_PRODUCTS_DIR; };
3636
93F174421BD0707D007E7DFC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
37-
93F174441BD0707D007E7DFC /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
37+
93F174441BD0707D007E7DFC /* SJEditorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SJEditorViewController.swift; sourceTree = "<group>"; };
3838
93F174461BD0707D007E7DFC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3939
93F174491BD0707D007E7DFC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
4040
93F1744B1BD0707D007E7DFC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -84,7 +84,7 @@
8484
isa = PBXGroup;
8585
children = (
8686
93F174421BD0707D007E7DFC /* AppDelegate.swift */,
87-
93F174441BD0707D007E7DFC /* ViewController.swift */,
87+
93F174441BD0707D007E7DFC /* SJEditorViewController.swift */,
8888
9361FD131BD18558001ED533 /* LineNumberRulerView.swift */,
8989
93F174461BD0707D007E7DFC /* Assets.xcassets */,
9090
93F174481BD0707D007E7DFC /* Main.storyboard */,
@@ -206,7 +206,7 @@
206206
files = (
207207
93CDE7721BD1A00B00B5B234 /* SJTextView.swift in Sources */,
208208
93F174601BD070AA007E7DFC /* JSONHelper.swift in Sources */,
209-
93F174451BD0707D007E7DFC /* ViewController.swift in Sources */,
209+
93F174451BD0707D007E7DFC /* SJEditorViewController.swift in Sources */,
210210
9361FD141BD18558001ED533 /* LineNumberRulerView.swift in Sources */,
211211
93F174431BD0707D007E7DFC /* AppDelegate.swift in Sources */,
212212
);

SwiftyJSONAccelerator/Base.lproj/Main.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@
668668
<!--SwiftyJSONAccelerator-->
669669
<scene sceneID="hIz-AP-VOD">
670670
<objects>
671-
<viewController title="SwiftyJSONAccelerator" id="XfG-lQ-9wD" customClass="ViewController" customModule="SwiftyJSONAccelerator" customModuleProvider="target" sceneMemberID="viewController">
671+
<viewController title="SwiftyJSONAccelerator" id="XfG-lQ-9wD" customClass="SJEditorViewController" customModule="SwiftyJSONAccelerator" customModuleProvider="target" sceneMemberID="viewController">
672672
<view key="view" id="m2S-Jp-Qdl">
673673
<rect key="frame" x="0.0" y="0.0" width="593" height="460"/>
674674
<autoresizingMask key="autoresizingMask"/>

SwiftyJSONAccelerator/JSONHelper.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public class JSONHelper {
1414
/**
1515
Validates if te string that is provided can be converted into a valid JSON.
1616

17-
- parameter jsonString: Input string that is to be checked as JSON.
17+
- parameters:
18+
- jsonString: Input string that is to be checked as JSON.
1819

1920
- returns: Bool indicating if it is a JSON or NSError with the error about the validation.
2021
*/
@@ -26,7 +27,8 @@ public class JSONHelper {
2627
/**
2728
Converts the given string into an Object.
2829

29-
- parameter jsonString: Input string that has to be converted.
30+
- parameters:
31+
- jsonString: Input string that has to be converted.
3032

3133
- returns: Bool indicating if the process was successful, Object if it worked else NSError.
3234
*/
@@ -49,7 +51,8 @@ public class JSONHelper {
4951
/**
5052
Formats the given string into beautiful JSON with indentation.
5153

52-
- parameter jsonString: JSON string that has to be formatted.
54+
- parameters:
55+
- jsonString: JSON string that has to be formatted.
5356

5457
- returns: String with JSON but well formatted.
5558
*/
@@ -65,7 +68,8 @@ public class JSONHelper {
6568
/**
6669
Formats the given Object into beautiful JSON with indentation.
6770

68-
- parameter object: Object that has to be formatted.
71+
- parameters:
72+
- object: Object that has to be formatted.
6973

7074
- returns: String with JSON but well formatted.
7175
*/

SwiftyJSONAccelerator/ViewController.swift renamed to SwiftyJSONAccelerator/SJEditorViewController.swift

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// ViewController.swift
2+
// SJEditorViewController.swift
33
// SwiftyJSONAccelerator
44
//
55
// Created by Karthik on 16/10/2015.
@@ -8,12 +8,15 @@
88

99
import Cocoa
1010

11-
class ViewController: NSViewController, NSTextViewDelegate {
11+
/// View for the processing of the content and generation of the files.
12+
class SJEditorViewController: NSViewController, NSTextViewDelegate {
1213

14+
// MARK: Outlet files.
1315
@IBOutlet var textView: SJTextView?
1416
@IBOutlet var messageLabel: NSTextField?
1517
@IBOutlet var errorImageView: NSImageView?
1618

19+
// MARK: View methods
1720
override func viewDidLoad() {
1821
super.viewDidLoad()
1922

@@ -29,7 +32,7 @@ class ViewController: NSViewController, NSTextViewDelegate {
2932
// Update the view, if already loaded.
3033
}
3134
}
32-
35+
// MARK: Actions
3336
@IBAction func format(sender: AnyObject?) {
3437

3538
if textView?.string?.characters.count == 0 {
@@ -49,6 +52,20 @@ class ViewController: NSViewController, NSTextViewDelegate {
4952
textView!.lnv_textDidChange(NSNotification.init(name: NSTextDidChangeNotification, object: nil))
5053
}
5154

55+
// MARK: Internal Methods
56+
57+
/**
58+
Get the line number, column and the character for the position in the given string.
59+
60+
- parameters:
61+
- string: The JSON string that is in the textview.
62+
- position: the location where the error is.
63+
64+
- returns:
65+
- character: the string that was causing the issue.
66+
- line: the linenumber where the error was.
67+
- column: the column where the error was.
68+
*/
5269
func characterRowAndLineAt(string: String,position: Int) -> (character: String, line: Int, column:Int) {
5370
var lineNumber = 0
5471
var characterPosition = 0
@@ -70,9 +87,13 @@ class ViewController: NSViewController, NSTextViewDelegate {
7087
return ("", 0,0)
7188
}
7289

90+
/**
91+
Handle Error message that is provided by the JSON helper and extract the message and showing them accordingly.
7392

93+
- parameters:
94+
- error: NSError that was provided.
95+
*/
7496
func handleError(error: NSError?) {
75-
let alert: NSAlert = NSAlert.init(error: error!)
7697
if let _ = error!.userInfo["debugDescription"] as? String? {
7798
let message: String = error!.userInfo["NSDebugDescription"]! as! String
7899
let numbers: [String] = message.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)
@@ -91,22 +112,41 @@ class ViewController: NSViewController, NSTextViewDelegate {
91112
invalidJSONError(message)
92113
}
93114
}
94-
alert.runModal()
95115
}
96116

117+
///MARK: Resetting and showing error messages
118+
119+
/**
120+
Reset the whole error view with no image and message.
121+
*/
97122
func resetErrorImage() {
98123
errorImageView?.image = nil
99124
messageLabel?.stringValue = ""
100125
}
101126

127+
/**
128+
Show that the JSON is fine with proper icon.
129+
*/
102130
func correctJSONMessage() {
103131
errorImageView?.image = NSImage.init(named: "success")
104132
messageLabel?.stringValue = "Valid JSON!"
105133
}
106134

135+
/**
136+
Show the invalid JSON error with proper error and message.
137+
138+
- parameters:
139+
- message: Error message that is to be shown.
140+
*/
107141
func invalidJSONError(message: String) {
108-
errorImageView?.image = NSImage.init(named: "failure")
142+
errorImageView?.image = NSImage.init(named: "failure")
109143
messageLabel?.stringValue = message
110144
}
145+
146+
//MARK: TextView Delegate
147+
func textDidChange(notification: NSNotification) {
148+
format(textView)
149+
}
150+
111151
}
112152

SwiftyJSONAccelerator/SJTextView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Cocoa
1010

11+
/// A textview customization to handle formatting and handling removal of quotes.
1112
class SJTextView: NSTextView {
1213

1314
override init(frame frameRect: NSRect, textContainer container: NSTextContainer?) {

0 commit comments

Comments
 (0)