Skip to content

Commit

Permalink
Updated for 0.6.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Nov 9, 2017
1 parent e27f698 commit 494e8eb
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 10 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Change Log

## [0.6.0](https://github.com/schibsted/layout/releases/tag/0.6.0) (2017-11-09)

- Outlets can now be set using an expression as long the result is constant (see README.md for details)
- Error messages now include the name of the Layout XML file where the error occured
- Improved error messages, including bug fixes and better suggestions for mistyped property names
- Added `childNode(withID:)` and `children(withID:)` methods to `LayoutNode` for looking up child nodes
- The `layoutNode` property for Layout-managed table and collection view cells is now public
- Better constant analysis, which should improve performance when updating mostly-static views
- Fixed incorrect error message when expression is missing a closing brace
- Dropped support for Swift 3.1 and Xcode 8.3.3 (this was broken in the previous release anyway)
- Fixed string and character-related warnings in Xcode 9
- Minor breaking changes to LayoutError API

## [0.5.9](https://github.com/schibsted/layout/releases/tag/0.5.9) (2017-11-02)

- Fixed assertion failure caused by view layout triggering during a Layout update
Expand Down
2 changes: 1 addition & 1 deletion EditorExtension/Application/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.5.9</string>
<string>0.6.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion EditorExtension/Extension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>0.5.9</string>
<string>0.6.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSMinimumSystemVersion</key>
Expand Down
4 changes: 2 additions & 2 deletions Layout.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Layout",
"version": "0.5.9",
"version": "0.6.0",
"license": {
"type": "MIT",
"file": "LICENSE.md"
Expand All @@ -10,7 +10,7 @@
"authors": "Nick Lockwood",
"source": {
"git": "https://github.com/schibsted/layout.git",
"tag": "0.5.9"
"tag": "0.6.0"
},
"default_subspecs": "Core",
"subspecs": [
Expand Down
2 changes: 1 addition & 1 deletion Layout/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>0.5.9</string>
<string>0.6.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
3 changes: 3 additions & 0 deletions Layout/LayoutNode+Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ extension LayoutNode {
}
expressions[bodyExpression] = body
}
if let outlet = outlet {
expressions["outlet"] = outlet
}
try self.init(
class: _class,
id: layout.id,
Expand Down
2 changes: 1 addition & 1 deletion LayoutTests/UtilitiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest
@testable import Layout

class UtilitiesTests: XCTestCase {

// MARK: StringUtils

// Unicode scalars
Expand Down
2 changes: 1 addition & 1 deletion LayoutTool/Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ extension XMLNode {
.xmlEncoded(forAttribute: false)
.replacingOccurrences(of: "\\s*\\n\\s*", with: "\n\(indent)", options: .regularExpression)
if body.hasSuffix("\n\(indent)") {
body = String(body[body.startIndex ..< body.index(body.endIndex, offsetBy: -indent.characters.count)])
body = String(body[body.startIndex ..< body.index(body.endIndex, offsetBy: -indent.count)])
}
if indentFirstLine {
body = body.replacingOccurrences(of: "^\\s*", with: indent, options: .regularExpression)
Expand Down
2 changes: 1 addition & 1 deletion LayoutTool/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Foundation

/// The current LayoutTool version
let version = "0.5.9"
let version = "0.6.0"

extension String {
var inDefault: String { return "\u{001B}[39m\(self)" }
Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class MyViewController: LayoutViewController {

In this example we've bound the `LayoutNode` containing the `UILabel` to the `labelNode` property. A few things to note:

* There's no need to use the `@IBOutlet` attribute for your `outlet` property, but you can do so if you feel it makes the purpose clearer. If you do not use `@IBOutlet`, you may need to use `@objc` to ensure the property is visible to Layout at runtime.
* There's no need to use the `@IBOutlet` attribute for your `outlet` property, but you can do so if you feel it makes the purpose clearer. If you do not use `@IBOutlet`, you will need to use `@objc` to ensure the property is visible to Layout at runtime.
* The type of the `outlet` property can be either `LayoutNode` or a `UIView` subclass that's compatible with the view managed by the node. The syntax is the same in either case - the type will be checked at runtime, and an error will be thrown if it doesn't match up.
* In the example above we have used Swift's `#keyPath` syntax to specify the `outlet` value, for better static validation. This is recommended, but not required.
* The `labelNode` outlet in the example has been marked as Optional. It is common to use Implicitly Unwrapped Optionals (IUOs) when defining IBOutlets, and that will work with Layout too, but it will result in a hard crash if you make a mistake in your XML and then try to access the outlet. Using regular Optionals means XML errors can be trapped and fixed without restarting the app.
Expand All @@ -463,7 +463,25 @@ To specify outlet bindings when using XML templates, use the `outlet` attribute:
</UIView>
```

In this case we lose the static validation provided by `#keyPath`, but Layout still performs a runtime check and will throw a graceful error in the event of a typo or type mismatch, rather than crashing. Note that although the `outlet` attribute is set in the same way as an expression, it is just a constant string, and cannot contain expression logic (although it can be commented-out using `//`, as with all other attributes).
In this case we lose the static validation provided by `#keyPath`, but Layout still performs a runtime check and will throw a graceful error in the event of a typo or type mismatch, rather than crashing.

Outlets can also be set using an expression instead of a literal value. This is useful if you wish to pass the outlet in to the template via a parameter, for example:

```xml
<UIView>
<param name="labelOutlet" type="String"/>

<UILabel
outlety="{labelOutlet}"
text="Hello World"
/>
</UIView>
```

The type of the parameter in this case must be `String`, and not `UILabel` as you might expect. The reason for this is that the outlet is a KeyPath that references a property of the layout's owner (typically a view controller), not a direct reference to the view itself.

**Note:** Outlet expressions must be set using a constant or literal value, and cannot be changed once set. Attempting to set the outlet using a state variable or other dynamic value will result in an error.


## Delegates

Expand Down

0 comments on commit 494e8eb

Please sign in to comment.