Skip to content

Commit 11087ed

Browse files
committed
Merge branch 'develop'
2 parents ea005c8 + d8c8e39 commit 11087ed

File tree

5 files changed

+43
-27
lines changed

5 files changed

+43
-27
lines changed

R.swift.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "R.swift"
4-
s.version = "0.8.1"
4+
s.version = "0.8.2"
55
s.summary = "Use strong typed, autocompleted resources like images and segues in Swift"
66

77
s.description = <<-DESC
@@ -22,7 +22,7 @@ Pod::Spec.new do |s|
2222

2323
s.platform = :ios, "7.0"
2424

25-
s.source = { :http => "https://github.com/mac-cain13/R.swift/releases/download/v0.8.1/rswift-0.8.1.zip" }
25+
s.source = { :http => "https://github.com/mac-cain13/R.swift/releases/download/v0.8.2/rswift-0.8.2.zip" }
2626

2727
s.preserve_paths = "rswift"
2828

R.swift/func.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ func storyboardStructForStoryboard(storyboard: Storyboard) -> Struct {
125125

126126
let validateImagesLines = distinct(storyboard.usedImageIdentifiers)
127127
.map { "assert(UIImage(named: \"\($0)\") != nil, \"[R.swift] Image named '\($0)' is used in storyboard '\(storyboard.name)', but couldn't be loaded.\")" }
128-
let validateImagesFunc = Function(isStatic: true, name: "validateImages", parameters: [], returnType: Type._Void, body: join("\n", validateImagesLines))
128+
let validateImagesFunc = Function(isStatic: true, name: "validateImages", generics: nil, parameters: [], returnType: Type._Void, body: join("\n", validateImagesLines))
129129

130130
let validateViewControllersLines = catOptionals(storyboard.viewControllers
131131
.map { vc in
132132
vc.storyboardIdentifier.map {
133133
"assert(\(sanitizedSwiftName($0)) != nil, \"[R.swift] ViewController with identifier '\(sanitizedSwiftName($0))' could not be loaded from storyboard '\(storyboard.name)' as '\(vc.type)'.\")"
134134
}
135135
})
136-
let validateViewControllersFunc = Function(isStatic: true, name: "validateViewControllers", parameters: [], returnType: Type._Void, body: join("\n", validateViewControllersLines))
136+
let validateViewControllersFunc = Function(isStatic: true, name: "validateViewControllers", generics: nil, parameters: [], returnType: Type._Void, body: join("\n", validateViewControllersLines))
137137

138138
return Struct(type: Type(name: sanitizedSwiftName(storyboard.name)), lets: [], vars: instanceVars + initialViewControllerVar + viewControllerVars, functions: [validateImagesFunc, validateViewControllersFunc], structs: [])
139139
}
@@ -168,6 +168,7 @@ func nibStructForNib(nib: Nib) -> Struct {
168168
let instantiateFunc = Function(
169169
isStatic: false,
170170
name: "instantiateWithOwner",
171+
generics: nil,
171172
parameters: instantiateParameters,
172173
returnType: Type(name: "[AnyObject]"),
173174
body: "return instance.instantiateWithOwner(ownerOrNil, options: optionsOrNil)"
@@ -179,9 +180,10 @@ func nibStructForNib(nib: Nib) -> Struct {
179180
Function(
180181
isStatic: false,
181182
name: "\($0.ordinal.word)View",
183+
generics: nil,
182184
parameters: instantiateParameters,
183185
returnType: $0.view.asOptional(),
184-
body: "return \(instantiateFunc.swiftName)(ownerOrNil, options: optionsOrNil)[\($0.ordinal.number - 1)] as? \($0.view)"
186+
body: "return \(instantiateFunc.callName)(ownerOrNil, options: optionsOrNil)[\($0.ordinal.number - 1)] as? \($0.view)"
185187
)
186188
}
187189

@@ -231,7 +233,7 @@ func varFromReusable(reusable: Reusable) -> Var {
231233
// Validation
232234

233235
func validateAllFunctionWithStoryboards(storyboards: [Storyboard]) -> Function {
234-
return Function(isStatic: true, name: "validate", parameters: [], returnType: Type._Void, body: join("\n", storyboards.map(swiftCallStoryboardValidators)))
236+
return Function(isStatic: true, name: "validate", generics: nil, parameters: [], returnType: Type._Void, body: join("\n", storyboards.map(swiftCallStoryboardValidators)))
235237
}
236238

237239
func swiftCallStoryboardValidators(storyboard: Storyboard) -> String {

R.swift/types.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,21 @@ struct Let: Printable {
139139
struct Function: Printable {
140140
let isStatic: Bool
141141
let name: String
142+
let generics: String?
142143
let parameters: [Parameter]
143144
let returnType: Type
144145
let body: String
145146

146-
var swiftName: String {
147+
var callName: String {
147148
return sanitizedSwiftName(name, lowercaseFirstCharacter: true)
148149
}
149150

150151
var description: String {
151152
let staticString = isStatic ? "static " : ""
153+
let genericsString = generics.map { "<\($0)>" } ?? ""
152154
let parameterString = join(", ", parameters)
153155
let returnString = Type._Void == returnType ? "" : " -> \(returnType)"
154-
return "\(staticString)func \(swiftName)(\(parameterString))\(returnString) {\n\(indent(body))\n}"
156+
return "\(staticString)func \(callName)\(genericsString)(\(parameterString))\(returnString) {\n\(indent(body))\n}"
155157
}
156158

157159
struct Parameter: Printable {

R.swift/values.swift

+24-12
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ let ReuseIdentifierUITableViewExtension = Extension(
6161
functions: [
6262
Function(
6363
isStatic: false,
64-
name: "dequeueReusableCellWithIdentifier<T : \(Type._UITableViewCell)>",
64+
name: "dequeueReusableCellWithIdentifier",
65+
generics: "T : \(Type._UITableViewCell)",
6566
parameters: [
6667
Function.Parameter(name: "identifier", type: ReuseIdentifier.type),
6768
Function.Parameter(name: "forIndexPath", localName: "indexPath", type: Type._NSIndexPath.asOptional(), defaultValue: "nil")
@@ -72,7 +73,8 @@ let ReuseIdentifierUITableViewExtension = Extension(
7273

7374
Function(
7475
isStatic: false,
75-
name: "dequeueReusableCellWithIdentifier<T : \(Type._UITableViewCell)>",
76+
name: "dequeueReusableCellWithIdentifier",
77+
generics: "T : \(Type._UITableViewCell)",
7678
parameters: [
7779
Function.Parameter(name: "identifier", type: ReuseIdentifier.type),
7880
],
@@ -82,7 +84,8 @@ let ReuseIdentifierUITableViewExtension = Extension(
8284

8385
Function(
8486
isStatic: false,
85-
name: "dequeueReusableHeaderFooterViewWithIdentifier<T : \(Type._UITableViewHeaderFooterView)>",
87+
name: "dequeueReusableHeaderFooterViewWithIdentifier",
88+
generics: "T : \(Type._UITableViewHeaderFooterView)",
8689
parameters: [
8790
Function.Parameter(name: "identifier", type: ReuseIdentifier.type),
8891
],
@@ -92,7 +95,8 @@ let ReuseIdentifierUITableViewExtension = Extension(
9295

9396
Function(
9497
isStatic: false,
95-
name: "registerNib<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UITableViewCell>",
98+
name: "registerNib",
99+
generics: "T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UITableViewCell",
96100
parameters: [
97101
Function.Parameter(name: "nibResource", type: Type(name: "T"))
98102
],
@@ -102,7 +106,8 @@ let ReuseIdentifierUITableViewExtension = Extension(
102106

103107
Function(
104108
isStatic: false,
105-
name: "registerNibs<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UITableViewCell>",
109+
name: "registerNibs",
110+
generics: "T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UITableViewCell",
106111
parameters: [
107112
Function.Parameter(name: "nibResources", type: Type(name: "[T]"))
108113
],
@@ -112,7 +117,8 @@ let ReuseIdentifierUITableViewExtension = Extension(
112117

113118
Function(
114119
isStatic: false,
115-
name: "registerNibForHeaderFooterView<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UIView>",
120+
name: "registerNibForHeaderFooterView",
121+
generics: "T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UIView",
116122
parameters: [
117123
Function.Parameter(name: "nibResource", type: Type(name: "T"))
118124
],
@@ -127,7 +133,8 @@ let ReuseIdentifierUICollectionViewExtension = Extension(
127133
functions: [
128134
Function(
129135
isStatic: false,
130-
name: "dequeueReusableCellWithReuseIdentifier<T : \(Type._UICollectionViewCell)>",
136+
name: "dequeueReusableCellWithReuseIdentifier",
137+
generics: "T: \(Type._UICollectionViewCell)",
131138
parameters: [
132139
Function.Parameter(name: "identifier", type: ReuseIdentifier.type),
133140
Function.Parameter(name: "forIndexPath", localName: "indexPath", type: Type._NSIndexPath)
@@ -138,7 +145,8 @@ let ReuseIdentifierUICollectionViewExtension = Extension(
138145

139146
Function(
140147
isStatic: false,
141-
name: "dequeueReusableSupplementaryViewOfKind<T : \(Type._UICollectionReusableView)>",
148+
name: "dequeueReusableSupplementaryViewOfKind",
149+
generics: "T: \(Type._UICollectionReusableView)",
142150
parameters: [
143151
Function.Parameter(name: "elementKind", type: Type._String),
144152
Function.Parameter(name: "withReuseIdentifier", localName: "identifier", type: ReuseIdentifier.type),
@@ -150,7 +158,8 @@ let ReuseIdentifierUICollectionViewExtension = Extension(
150158

151159
Function(
152160
isStatic: false,
153-
name: "registerNib<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionViewCell>",
161+
name: "registerNib",
162+
generics: "T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionViewCell",
154163
parameters: [
155164
Function.Parameter(name: "nibResource", type: Type(name: "T"))
156165
],
@@ -160,7 +169,8 @@ let ReuseIdentifierUICollectionViewExtension = Extension(
160169

161170
Function(
162171
isStatic: false,
163-
name: "registerNibs<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionViewCell>",
172+
name: "registerNibs",
173+
generics: "T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionViewCell",
164174
parameters: [
165175
Function.Parameter(name: "nibResources", type: Type(name: "[T]"))
166176
],
@@ -170,7 +180,8 @@ let ReuseIdentifierUICollectionViewExtension = Extension(
170180

171181
Function(
172182
isStatic: false,
173-
name: "registerNib<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionReusableView>",
183+
name: "registerNib",
184+
generics: "T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionReusableView",
174185
parameters: [
175186
Function.Parameter(name: "nibResource", type: Type(name: "T")),
176187
Function.Parameter(name: "forSupplementaryViewOfKind", localName: "kind", type: Type._String)
@@ -181,7 +192,8 @@ let ReuseIdentifierUICollectionViewExtension = Extension(
181192

182193
Function(
183194
isStatic: false,
184-
name: "registerNibs<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionReusableView>",
195+
name: "registerNibs",
196+
generics: "T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionReusableView",
185197
parameters: [
186198
Function.Parameter(name: "nibResources", type: Type(name: "[T]"))
187199
],

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ _Tool to get strong typed, autocompleted resources like images, cells and segues
33

44
## Why use this?
55

6-
You currently type:
6+
It makes your code that uses resources:
7+
- **Fully typed**, less casting and guessing what a method will return
8+
- **Compiletime checked**, no more incorrect strings that make your app crash on runtime
9+
- **Autocompleted**, never have to guess that image name again
10+
11+
Currently you type:
712
```swift
813
let icon = UIImage(names: "settings-icon")
914
let cell = dequeueReusableCellWithReuseIdentifier("textCell", forIndexPath: indexPath) as? TextCell
@@ -12,16 +17,11 @@ performSegueWithIdentifier("openSettings")
1217

1318
With R.swift it becomes:
1419
```swift
15-
let icon = R.images.settingsIcon
20+
let icon = R.image.settingsIcon
1621
let cell = dequeueReusableCellWithReuseIdentifier(R.reuseIdentifier.textCell, forIndexPath: indexPath)
1722
performSegueWithIdentifier(R.segue.openSettings)
1823
```
1924

20-
It makes your code that uses resources:
21-
- **Fully typed**, less casting and guessing what a method will return
22-
- **Compiletime checked**, no more incorrect strings that make your app crash on runtime
23-
- **Autocompleted**, never have to guess that image name again
24-
2525
## Usage
2626

2727
After installing R.swift into your project you can use the `R`-struct to access resources. If the struct is outdated just build and R.swift will correct any missing/changed/added resources.

0 commit comments

Comments
 (0)