Skip to content

Commit 9a9ba6c

Browse files
author
Karthikeya Udupa KM
committed
Merge pull request #27 from insanoid/releases/v0.0.6
Releases/v0.0.6
2 parents 2c28908 + 241bc3b commit 9a9ba6c

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

SwiftyJSONAccelerator/LineNumberRulerView.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ extension NSTextView {
5353
}
5454

5555
postsFrameChangedNotifications = true
56-
NSNotificationCenter.defaultCenter().addObserver(self, selector: "lnv_framDidChange:", name: NSViewFrameDidChangeNotification, object: self)
57-
58-
NSNotificationCenter.defaultCenter().addObserver(self, selector: "lnv_textDidChange:", name: NSTextDidChangeNotification, object: self)
56+
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(NSTextView.lnv_framDidChange(_:)), name: NSViewFrameDidChangeNotification, object: self)
57+
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(NSTextView.lnv_textDidChange(_:)), name: NSTextDidChangeNotification, object: self)
5958
}
6059

6160
func lnv_framDidChange(notification: NSNotification) {
@@ -141,12 +140,12 @@ class LineNumberRulerView: NSRulerView {
141140
}
142141

143142
// Move to next glyph line
144-
glyphLineCount++
143+
glyphLineCount += 1
145144
glyphIndexForGlyphLine = NSMaxRange(effectiveRange)
146145
}
147146

148147
glyphIndexForStringLine = NSMaxRange(glyphRangeForStringLine)
149-
lineNumber++
148+
lineNumber += 1
150149
}
151150

152151
// Draw line number for the extra line at the end of the text

SwiftyJSONAccelerator/SJEditorViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,16 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
170170
var lineNumber = 0
171171
var characterPosition = 0
172172
for line in string.componentsSeparatedByString("\n") {
173-
lineNumber++
173+
lineNumber += 1
174174
var columnNumber = 0
175175
for column in line.characters {
176-
characterPosition++
177-
columnNumber++
176+
characterPosition += 1
177+
columnNumber += 1
178178
if characterPosition == position {
179179
return (String(column), lineNumber, columnNumber )
180180
}
181181
}
182-
characterPosition++
182+
characterPosition += 1
183183
if characterPosition == position {
184184
return ("\n", lineNumber, columnNumber+1 )
185185
}

SwiftyJSONAccelerator/SJModelGenerator.swift

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public class ModelGenerator {
197197

198198
if self.supportNSCoding! {
199199
if let nscodingBase = try? String(contentsOfFile: NSBundle.mainBundle().pathForResource("NSCodingTemplate", ofType: "txt")!) {
200-
content = content.stringByReplacingOccurrencesOfString("{NSCODING_PROTOCOL_SUPPORT}", withString: ", NSCoding, NSObject")
200+
content = content.stringByReplacingOccurrencesOfString("{NSCODING_PROTOCOL_SUPPORT}", withString: ", NSCoding")
201201
content = content.stringByReplacingOccurrencesOfString("{NSCODING_SUPPORT}", withString: nscodingBase)
202202

203203
content = content.stringByReplacingOccurrencesOfString("{ENCODERS}", withString: encoders)
@@ -318,7 +318,7 @@ public class ModelGenerator {
318318
- returns: A generated string representation of the variable name.
319319
*/
320320
internal func variableNameBuilder(variableName: String) -> String {
321-
var variableName = replaceInternalKeywordsForVariableName(variableName).stringByReplacingOccurrencesOfString("_", withString: " ")
321+
var variableName = replaceSeperatorsWithSpace(replaceInternalKeywordsForVariableName(variableName))
322322
variableName = variableName.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
323323
var finalVariableName: String = ""
324324
for (index, element) in variableName.componentsSeparatedByString(" ").enumerate() {
@@ -335,6 +335,13 @@ public class ModelGenerator {
335335

336336
}
337337

338+
/**
339+
Replaces the seperator characters between words with space.
340+
*/
341+
internal func replaceSeperatorsWithSpace(variableName: String) -> String {
342+
return variableName.stringByReplacingOccurrencesOfString("_", withString: " ").stringByReplacingOccurrencesOfString("-", withString: " ")
343+
}
344+
338345
/**
339346
Generate a variable name to store the key of the variable in the JSON for later use (generating JSON file, encoding and decoding). the format is k{ClassName}{VariableName}Key.
340347

@@ -343,9 +350,10 @@ public class ModelGenerator {
343350

344351
- returns: A generated string that can be used to store the key of the variable in the JSON.
345352
*/
346-
internal func variableNameKeyBuilder(className: String, var variableName: String) -> String {
347-
variableName.replaceRange(variableName.startIndex...variableName.startIndex, with: String(variableName[variableName.startIndex]).uppercaseString)
348-
return "k\(className)\(variableName)Key"
353+
internal func variableNameKeyBuilder(className: String, variableName: String) -> String {
354+
var _variableName = variableName
355+
_variableName.replaceRange(variableName.startIndex...variableName.startIndex, with: String(variableName[variableName.startIndex]).uppercaseString)
356+
return "k\(className)\(_variableName)Key"
349357
}
350358

351359
/**
@@ -445,9 +453,9 @@ public class ModelGenerator {
445453
- parameter key: Key against which the value is stored.
446454
- returns: A single line declaration of the variable which is an array of primitive kind.
447455
*/
448-
internal func initalizerForPrimitiveVariableArray(variableName: String, key: String, var type: String) -> String {
449-
type = typeToSwiftType(type)
450-
return "\t\t\(variableName) = []\n\t\tif let items = json[\(key)].array {\n\t\t\tfor item in items {\n\t\t\t\tif let tempValue = item.\(type) {\n\t\t\t\t\(variableName)?.append(tempValue)\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t\(variableName) = nil\n\t\t}"
456+
internal func initalizerForPrimitiveVariableArray(variableName: String, key: String, type: String) -> String {
457+
let _type = typeToSwiftType(type)
458+
return "\t\t\(variableName) = []\n\t\tif let items = json[\(key)].array {\n\t\t\tfor item in items {\n\t\t\t\tif let tempValue = item.\(_type) {\n\t\t\t\t\(variableName)?.append(tempValue)\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t\(variableName) = nil\n\t\t}"
451459
}
452460

453461
//MARK: Encoders and Decoder Generators
@@ -648,9 +656,10 @@ public class ModelGenerator {
648656
- parameter type: VariableType
649657
- returns: swift variable type.
650658
*/
651-
internal func typeToSwiftType(var type: String) -> String {
652-
type.replaceRange(type.startIndex...type.startIndex, with: String(type[type.startIndex]).lowercaseString)
653-
return type
659+
internal func typeToSwiftType(type: String) -> String {
660+
var _type = type
661+
_type.replaceRange(type.startIndex...type.startIndex, with: String(type[type.startIndex]).lowercaseString)
662+
return _type
654663
}
655664

656665

SwiftyJSONAccelerator/SwiftyJSON.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ public struct JSONGenerator : GeneratorType {
385385
switch self.type {
386386
case .Array:
387387
if let o = self.arrayGenerate!.next() {
388-
return (String(self.arrayIndex++), JSON(o))
388+
let oldValue = self.arrayIndex
389+
self.arrayIndex+=1
390+
return (String(oldValue), JSON(o))
389391
} else {
390392
return nil
391393
}

0 commit comments

Comments
 (0)