-
Notifications
You must be signed in to change notification settings - Fork 822
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
Generate code data models properly #249
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Tests/Fixtures/TestProject/App_iOS/Model.xcdatamodeld/Model.xcdatamodel/contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="13772" systemVersion="17D47" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier=""> | ||
<entity name="Entity" representedClassName="Entity" syncable="YES" codeGenerationType="class"/> | ||
<elements> | ||
<element name="Entity" positionX="-63" positionY="-18" width="128" height="45"/> | ||
</elements> | ||
</model> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//https://gist.github.com/kristopherjohnson/543687c763cd6e524c91 | ||
|
||
import Foundation | ||
|
||
/// Find first differing character between two strings | ||
/// | ||
/// :param: s1 First String | ||
/// :param: s2 Second String | ||
/// | ||
/// :returns: .DifferenceAtIndex(i) or .NoDifference | ||
public func firstDifferenceBetweenStrings(_ s1: String, _ s2: String) -> FirstDifferenceResult { | ||
let len1 = s1.count | ||
let len2 = s2.count | ||
|
||
let lenMin = min(len1, len2) | ||
|
||
for i in 0..<lenMin { | ||
if (s1 as NSString).character(at: i) != (s2 as NSString).character(at: i) { | ||
return .DifferenceAtIndex(i) | ||
} | ||
} | ||
|
||
if len1 < len2 { | ||
return .DifferenceAtIndex(len1) | ||
} | ||
|
||
if len2 < len1 { | ||
return .DifferenceAtIndex(len2) | ||
} | ||
|
||
return .NoDifference | ||
} | ||
|
||
|
||
/// Create a formatted String representation of difference between strings | ||
/// | ||
/// :param: s1 First string | ||
/// :param: s2 Second string | ||
/// | ||
/// :returns: a string, possibly containing significant whitespace and newlines | ||
public func prettyFirstDifferenceBetweenStrings(_ s1: String, _ s2: String, previewPrefixLength: Int = 25, previewSuffixLength:Int = 25) -> String { | ||
let firstDifferenceResult = firstDifferenceBetweenStrings(s1, s2) | ||
|
||
func diffString(at index: Int, _ s1: String, _ s2: String) -> String { | ||
let markerArrow = "\u{2b06}" // "⬆" | ||
let ellipsis = "\u{2026}" // "…" | ||
|
||
/// Given a string and a range, return a string representing that substring. | ||
/// | ||
/// If the range starts at a position other than 0, an ellipsis | ||
/// will be included at the beginning. | ||
/// | ||
/// If the range ends before the actual end of the string, | ||
/// an ellipsis is added at the end. | ||
func windowSubstring(_ s: String, _ range: NSRange) -> String { | ||
let validRange = NSMakeRange(range.location, min(range.length, s.count - range.location)) | ||
let substring = (s as NSString).substring(with: validRange) | ||
|
||
let prefix = range.location > 0 ? ellipsis : "" | ||
let suffix = (s.count - range.location > range.length) ? ellipsis : "" | ||
|
||
return "\(prefix)\(substring)\(suffix)" | ||
} | ||
|
||
// Show this many characters before and after the first difference | ||
let windowLength = previewPrefixLength + 1 + previewSuffixLength | ||
|
||
let windowIndex = max(index - previewPrefixLength, 0) | ||
let windowRange = NSMakeRange(windowIndex, windowLength) | ||
|
||
let sub1 = windowSubstring(s1, windowRange) | ||
let sub2 = windowSubstring(s2, windowRange) | ||
|
||
let markerPosition = min(previewSuffixLength, index) + (windowIndex > 0 ? 1 : 0) | ||
|
||
let markerPrefix = String(repeating: " ", count: markerPosition) | ||
let markerLine = "\(markerPrefix)\(markerArrow)" | ||
|
||
return "Difference at index \(index):\n\(sub1)\n\(sub2)\n\(markerLine)" | ||
} | ||
|
||
switch firstDifferenceResult { | ||
case .NoDifference: return "No difference" | ||
case .DifferenceAtIndex(let index): return diffString(at: index, s1, s2) | ||
} | ||
} | ||
|
||
|
||
/// Result type for firstDifferenceBetweenStrings() | ||
public enum FirstDifferenceResult { | ||
/// Strings are identical | ||
case NoDifference | ||
|
||
/// Strings differ at the specified index. | ||
/// | ||
/// This could mean that characters at the specified index are different, | ||
/// or that one string is longer than the other | ||
case DifferenceAtIndex(Int) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, CI was failing so I needed this to see why 😄