mac-cain13 / r.swift Goto Github PK
View Code? Open in Web Editor NEWStrong typed, autocompleted resources like images, fonts and segues in Swift projects
License: MIT License
Strong typed, autocompleted resources like images, fonts and segues in Swift projects
License: MIT License
Detect resources based on resource build step in the Xcode project file not based on browsing the users folders. This is would be way more reliable and prevent confusion of files that are missing or duplicated etc.
Hi,
I had an issue migrating our app to swift 2.0:
See:
ntnmrndn@a1d58b9
By forking and editing the source code, I noticed that the script is not being compiled from source but rather distributed as a binary.
While I'm convinced you are honest and while I could probably verify that the binary distributed is the same as the one I would be able to compile myself, I strongly believe it would be better for the user to compile directly the source on his computer, and launch the script using swift command line tools.
This makes it hard to reach it.
Do you have any plans as of yet to implement Carthage support for this repo?
Fantastic project by the way!
How should we handle this? When you have a Main.storyboard
and a Main.xcassets
we generate twe structs with the same name.
Possible solutions:
R.storyboard.*
and R.assets.*
, but this gives longer namesSomething like:
struct R {
static func validateStoryboardImages() {
assert(UIImage(named: "bla") != nil, "Err?!")
}
}
that we can call at application launch for debug builds, this would make sure old image don't linger around in your storyboard.
Add new feature parsing .strings file
It generates a file where UITableViewCell
and UICollectionView
(and more) are written as Uitableviewcell
and Uicollectionview
(or similar) and a project using it won't compile.
On iOS, user can provide custom fonts through Info.plist's UIAppFonts.
It would be nice to provide completion for:
func R.font.appFonts.fontName(fontSize:14.0) -> UIFont!
var R.font.appFonts.fontName: String
Bonus:
R.font.system.helvetica(fontSize:14.0) -> UIFont!
var R.font.system.helvetica: String
This is a bit complicated since with have to find the right names for the fonts, but it would be a really nice feature :)
Maybe I can find some time to implement that.
Can you give me a feedback before I start ?
As suggested by Tom on Q42 Slack:
Feature request voor R.swift:
Niet de struct in dezelfde namespace hebben als de waarde die ik nodig heb.
Ik moet gebruikenR.nib.textCell
, maar in de autocomplete zit ookR.nib.TextCell
, die ik nooit nodig heb.
Of op z'n minst postfix de naam, zodat het duidelijk is dat ik die niet wil:R.nib.TextCellNibResource
I think they should be completely out of the R-struct since it's a strictly supporting struct.
Like jpeg images.
Think this is something R.swift also could support!
Kan je hem toegankelijk maken op Cocoapods? 👼
Attempting to use R.swift in a project which has been converted to Swift 2 in Xcode 7 beta 5 results in a build error in R.generated.swift
which says 'Printable' has been renamed to 'CustomStringConvertible'
.
The offending code is:
struct ReuseIdentifier<T>: Printable {
let identifier: String
var description: String { return identifier }
}
I have some IBDesignable
classes that rely on images. Unfortunately using UIImage(named:)
doesn't work in Interface Builder, as Interface Builder creates separate bundles for each class which you're supposed to use when creating images. For example, I have the following code:
let bundle = NSBundle(forClass: self.dynamicType)
let image = UIImage(named: "chevronAccessory", inBundle: bundle, compatibleWithTraitCollection: nil)
return UIImageView(image: image)
"chevronAccessory"
is an image that exists in my asset catalog, so it would be nice if I could use R.swift to get the name.
Perhaps with the following format:
R.imageName.chevronAccessory
or
R.image.name.chevronAccessory
I'm not sure how typical this use case is, so it might not be worth decreasing the usability of images, but if you wanted to do so you could make images into a nested struct like nib
. So then you could have:
R.image.chevronAccessory.instance
R.image.chevronAccessory.insantiateWithBundle(bundle)
We should be able to do this by outputting something like this:
/path/to/file.swift:123: warning: This is the warning message
I'm wondering if we also could give an "auto-fix" suggestion.
Wil je mij de initiele viewController via R.swift aanbieden?
// <3 R.swift
let storyboard = R.storyboard.main.instance
let initialViewController = storyboard.instantiateInitialViewController() as UIViewController
@sdevos mentioned that identifiers are not really made for lookups, so should think about whether this is really a good idea.
Storyboard:
<navigationController storyboardIdentifier="modalShipmentResultNavigationController" id="zyq-w4-qbK" sceneMemberID="viewController">
Generates:
static var modalShipmentResultNavigationController: UIViewController? { return instance.instantiateViewControllerWithIdentifier("modalShipmentResultNavigationController") as? UIViewController }
Should be:
static var modalShipmentResultNavigationController: UINavigationController? { return instance.instantiateViewControllerWithIdentifier("modalShipmentResultNavigationController") as? UINavigationController }
registerNibForHeaderFooterView<T: NibResource where T: Reusable, T.T: UITableViewHeaderFooterView> is right。
please
I was wondering whether it would be possible to force unwrap the UIImage
s so that the different struct vars don't return an Optional
? Might seem scary but it shouldn't be too dangerous if the library is well tested. What do you think?
Hi there,
I was wondering if it would be possible to add another argument so that one can specify destination folder. I don't want to have the auto generated file in the root of the project folder but rather in a dedicated resources folder.
What do you think? I would implement this myself but I'm honestly a little confused with your project setup.
I've dragged the unzipped R.swift-master into my $SRCROOT and attempted to run script build phase with "$SRCROOT/rswift" "$SRCROOT", but all I get is "/Users/mlchild//Developer/Project/rswift: No such file or directory".
I understand I am likely an idiot, but cannot figure this out. Prefer not to use cocoapods.
We could generate full ManagedObjects in Swift (since Apple does that so poorly), but we also could make querying better by providing something like R.managedObject.car.color == "color"
that you can use a %K
value in a predicate.
xcode works fine with spaces in asset names, however R.swift generates invalid code
static var detail Disclosure: UIImage? { return UIImage(named: "Detail Disclosure") }
If you name your image of segue after a keyword like switch
the generated struct is invalid. I think good behavior would be:
See https://github.com/isagalaev/highlight.js/blob/master/src/languages/swift.js for a list of keywords etc.
the xcodeproj gem should be able to do this using prepare_command
This would make something like R.main.nextStepSegue
possible instead of the current string approach.
I would be a lot more comfortable using this if this had at least a few tests.
Great work though, I absolutely love this :)
Hi there,
First of all, thanks for opensourcing this project :)
I just integrated this with Cocoapods and there's something I couldn't understand. My project doesn't contain any storyboards, thus any segues neither; but after compiling the project, my R.generated.swift file has a storyboard struct, a segue struct with some segues that I couldn't understand where they came from. Also, the reuseIdentifier struct has many duplicate "Cell" reuseIdentifiers which causes the project not to compile. I couldn't understand where those came from either :) cos I don't have any cells in storyboards or nibs.
I hope I'm just confused and missing something :) because I'd love to use this a lot!
Thanks in advance and cheers!
Images I placed inside Assets.xcassets are not getting strong-typed.
Everything else seems to work file - storyboards/view-controllers/xibs etc.
I have integrated R.swift using pod in my project.
Using Swift 1.2
Xcode 6.4
Maybe we could do something with detecting unused images and warning the developer about it?!
I don't think it is not possible yet to initial an UIViewController with nib file like the example below.
/// Old way
SelectPlanViewController(nibName: "SelectPlanViewController", bundle: nil)
/// Should be
SelectPlanViewController(nibName: R.nib.selectPlanViewController.nibName, bundle: nil)
/// or even as extensions from UIViewController
SelectPlanViewController(rResource: R.nib.selectPlanViewController)
What do you think about it?
Xcode 7 beta 6
~: pod --version
0.39.0.beta.4
~: pod update
...
Project Run Script
"$PODS_ROOT/R.swift/rswift" "$SRCROOT/Project"
So file rswift doesn't copy on update
This would be an easy way to show more code before and after using R.swift and make users able to play with it.
Downsides:
Would be nice to write this:
let x = tableView.dequeueReusableCellWithIdentifier(R.reuseIdentifier.rerouteBusinessHoursCell, forIndexPath: indexPath)
instead of this:
let x = tableView.dequeueReusableCellWithIdentifier(R.reuseIdentifier.rerouteBusinessHoursCell, forIndexPath: indexPath) as RerouteBusinessHoursCell
Static shortcut items must be defined in Info.plist with the following keys under the UIApplicationShortcutItems array:
Key | Description |
---|---|
UIApplicationShortcutItemType (required) |
A required string delivered to your app when the user invokes the corresponding quick action. Your app can use this string to classify quick actions into types, and then to disambiguate among action types it receives. You don’t need to register your quick action types. |
UIApplicationShortcutItemTitle (required) | A string displayed to the user on the Home screen as the name of the quick action. If the title fits on one line, the system displays it as a single line quick action item. If the title is too long for one line and you have not specified a UIApplicationShortcutItemSubtitle string, the system displays the title on two lines. You can, optionally, internationalize a quick action title by employing your app’s InfoPlist.strings file. For guidance on how to do this, read Localizing Property List Values. |
UIApplicationShortcutItemSubtitle | An optional string that is displayed to the user on the Home screen, immediately below the corresponding title string. If you specify a subtitle for a quick action, the system displays the quick action title on a single line (perhaps just a portion of the title, followed by ellipsis character), no matter how long the title is. You can, optionally, internationalize a quick action subtitle by employing your app’s InfoPlist.strings file. For guidance on how to do this, read Localizing Property List Values. |
UIApplicationShortcutItemIconType | An optional string specifying the type of an icon from the system-provided library; see the UIApplicationShortcutIconType enumeration in UIApplicationShortcutIcon Class Reference. The icon is displayed in the set of quick actions for your app, along with the quick action's title, on the Home screen. |
UIApplicationShortcutItemIconFile | An optional string specifying an icon image to use from the app’s bundle, or the name of an image in an asset catalog. The icon is displayed before quick action title on the Home screen. Icons should be square, single color, and 35x35 points, as shown in these template files and as described in iOS Human Interface Guidelines. If you specify this key, the system ignores the UIApplicationShortcutItemIconType key. |
UIApplicationShortcutItemUserInfo | An optional, app-defined dictionary. One use for this dictionary is to provide app version information, as described in the “App Launch and App Update Considerations for Quick Actions” section of the overview in UIApplicationShortcutItem Class Reference. |
More info:
So UINib.init(nibName: "NotificationView", bundle: nil)
would become something like R.nib.notificationView
.
Currently the generated R.Swift
has a struct that implements Printable
:
struct ReuseIdentifier<T>: Printable {
let identifier: String
var description: String { return identifier }
}
Printable
has been replaced with CustomStringConvertible
with the introduction of Swift 2. Perhaps we could have a argument to pass a version of swift to generate the file for?
See #34 (comment):
Segues should be changed so they are an extension on the viewcontroller and not global things. This makes duplicates less likely and if in that situation there are duplicates they really are a problem so a warning is appropriate then.
This also would enable us to make typed segues in the end.
Would be cool if we could install this using Homebrew :)
Then we wouldn't need to have the binary in every single project folder.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.