Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mac-cain13 committed Jul 12, 2015
2 parents 948b237 + 897c906 commit db5be39
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions R.swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
D5EA0DEC1A3DF45600FFEBC4 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0610;
ORGANIZATIONNAME = "Mathijs Kadijk";
TargetAttributes = {
Expand Down
2 changes: 1 addition & 1 deletion R.swift/func.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func filterDirectoryContentsRecursively(fileManager: NSFileManager, filter: (NSU
}

func sanitizedSwiftName(name: String, lowercaseFirstCharacter: Bool = true) -> String {
var components = name.componentsSeparatedByString("-")
var components = name.componentsSeparatedByCharactersInSet(NSCharacterSet(charactersInString: " -"))
let firstComponent = components.removeAtIndex(0)
let swiftName = components.reduce(firstComponent) { $0 + $1.capitalizedString }
let capitalizedSwiftName = lowercaseFirstCharacter ? swiftName.lowercaseFirstCharacter : swiftName
Expand Down
10 changes: 7 additions & 3 deletions R.swift/types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,29 @@ struct Function: Printable {
let name: String
let localName: String?
let type: Type
let defaultValue: String?

var swiftName: String {
return sanitizedSwiftName(name, lowercaseFirstCharacter: true)
}

var description: String {
return localName.map({ "\(self.swiftName) \($0): \(type)" }) ?? "\(swiftName): \(type)"
let definition = localName.map({ "\(self.swiftName) \($0): \(type)" }) ?? "\(swiftName): \(type)"
return defaultValue.map({ "\(definition) = \($0)" }) ?? definition
}

init(name: String, type: Type) {
init(name: String, type: Type, defaultValue: String? = nil) {
self.name = name
self.localName = nil
self.type = type
self.defaultValue = defaultValue
}

init(name: String, localName: String?, type: Type) {
init(name: String, localName: String?, type: Type, defaultValue: String? = nil) {
self.name = name
self.localName = localName
self.type = type
self.defaultValue = defaultValue
}
}
}
Expand Down
36 changes: 33 additions & 3 deletions R.swift/values.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ let ReuseIdentifierUITableViewExtension = Extension(
name: "dequeueReusableCellWithIdentifier<T : \(Type._UITableViewCell)>",
parameters: [
Function.Parameter(name: "identifier", type: ReuseIdentifier.type),
Function.Parameter(name: "forIndexPath", localName: "indexPath", type: Type._NSIndexPath)
Function.Parameter(name: "forIndexPath", localName: "indexPath", type: Type._NSIndexPath.asOptional(), defaultValue: "nil")
],
returnType: Type(name: "T", genericType: nil, optional: true),
body: "return dequeueReusableCellWithIdentifier(identifier.identifier, forIndexPath: indexPath) as? T"
body: "if let indexPath = indexPath {\n return dequeueReusableCellWithIdentifier(identifier.identifier, forIndexPath: indexPath) as? T\n}\nreturn dequeueReusableCellWithIdentifier(identifier.identifier) as? T"
),

Function(
Expand Down Expand Up @@ -100,6 +100,16 @@ let ReuseIdentifierUITableViewExtension = Extension(
body: "registerNib(nibResource.instance, forCellReuseIdentifier: nibResource.reuseIdentifier.identifier)"
),

Function(
isStatic: false,
name: "registerNibs<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UITableViewCell>",
parameters: [
Function.Parameter(name: "nibResources", type: Type(name: "[T]"))
],
returnType: Type._Void,
body: "nibResources.map(registerNib)"
),

Function(
isStatic: false,
name: "registerNibForHeaderFooterView<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UIView>",
Expand Down Expand Up @@ -148,6 +158,16 @@ let ReuseIdentifierUICollectionViewExtension = Extension(
body: "registerNib(nibResource.instance, forCellWithReuseIdentifier: nibResource.reuseIdentifier.identifier)"
),

Function(
isStatic: false,
name: "registerNibs<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionViewCell>",
parameters: [
Function.Parameter(name: "nibResources", type: Type(name: "[T]"))
],
returnType: Type._Void,
body: "nibResources.map(registerNib)"
),

Function(
isStatic: false,
name: "registerNib<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionReusableView>",
Expand All @@ -157,7 +177,17 @@ let ReuseIdentifierUICollectionViewExtension = Extension(
],
returnType: Type._Void,
body: "registerNib(nibResource.instance, forSupplementaryViewOfKind: kind, withReuseIdentifier: nibResource.reuseIdentifier.identifier)"
)
),

Function(
isStatic: false,
name: "registerNibs<T: \(NibResourceProtocol.type) where T: \(ReusableProtocol.type), T.T: UICollectionReusableView>",
parameters: [
Function.Parameter(name: "nibResources", type: Type(name: "[T]"))
],
returnType: Type._Void,
body: "nibResources.map(registerNib)"
),
]
)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ _There is also a [short video](https://vimeo.com/122888912) of this instruction.

1. Add `pod 'R.swift'` to your [Podfile](http://cocoapods.org/#get_started) and run `pod install`
2. In XCode: Click on your project in the file list, choose your target under `TARGETS`, click the `Build Phases` tab and add a `New Run Script Phase` by clicking the little plus icon in the top left
3. Drag the new `Run Script` phase **above** the `Compile Sources` phase, expand it and paste the following script: `"$PODS_ROOT/R.swift/rswift" "$SRCROOT"`
3. Drag the new `Run Script` phase **above** the `Compile Sources` phase and **below** `Check Pods Manifest.lock`, expand it and paste the following script: `"$PODS_ROOT/R.swift/rswift" "$SRCROOT"`
4. Build your project, in Finder you will now see a `R.generated.swift` in the `$SRCROOT`-folder, drag the `R.generated.swift` files into your project and **uncheck** `Copy items if needed`

_Tip:_ Add the `*.generated.swift` pattern to your `.gitignore` file to prevent unnecessary conflicts.
Expand Down

0 comments on commit db5be39

Please sign in to comment.