Skip to content

Commit

Permalink
Update examples to Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mac-cain13 committed Sep 27, 2016
1 parent 427cb47 commit 3d1654e
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions Documentation/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ let lightFontTitle = R.font.acmeLight(size: 22)

*Vanilla*
```swift
let jsonURL = NSBundle.mainBundle().URLForResource("seed-data", withExtension: "json")
let jsonPath = NSBundle.mainBundle().pathForResource("seed-data", withExtension: "json")
let jsonURL = Bundle.main.url(forResource: "seed-data", withExtension: "json")
let jsonPath = Bundle.main.path(forResource: "seed-data", ofType: "json")
```

*With R.swift*
Expand Down Expand Up @@ -79,10 +79,10 @@ let welcomeMessage = NSLocalizedString("welcome.message", comment: "")
let settingsTitle = NSLocalizedString("title", tableName: "Settings", comment: "")

// Formatted strings
let welcomeName = String(format: NSLocalizedString("welcome.withName", comment: ""), locale: NSLocale.currentLocale(), "Alice")
let welcomeName = String(format: NSLocalizedString("welcome.withName", comment: ""), locale: NSLocale.current, "Alice")

// Stringsdict files
let progress = String(format: NSLocalizedString("copy.progress", comment: ""), locale: NSLocale.currentLocale(), 4, 23)
let progress = String(format: NSLocalizedString("copy.progress", comment: ""), locale: NSLocale.current, 4, 23)
```

*With R.swift*
Expand All @@ -104,7 +104,7 @@ let progress = R.string.localizable.copyProgress(completed: 4, total: 23)
```swift
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialTabBarController = storyboard.instantiateInitialViewController() as? UITabBarController
let settingsController = self.instantiateViewControllerWithIdentifier("settingsController") as? SettingsController
let settingsController = storyboard.instantiateViewController(withIdentifier: "settingsController") as? SettingsControllerSettingsController
```

*With R.swift*
Expand All @@ -119,26 +119,25 @@ let settingsController = R.storyboard.main.settingsController()
*Vanilla*
```swift
// Trigger segue with:
performSegueWithIdentifier("openSettings", sender: self)
performSegue(withIdentifier: "openSettings", sender: self)

// And then prepare it:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let settingsController = segue.destinationViewController as? SettingsController,
segue = segue as? CustomSettingsSegue
where segue.identifier == "openSettings" {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let settingsController = segue.destination as? SettingsController,
let segue = segue as? CustomSettingsSegue, segue.identifier == "openSettings" {
segue.animationType = .LockAnimation
settingsController.lockSettings = true
}
}
}
```

*With R.swift*
```swift
// Trigger segue with:
performSegueWithIdentifier(R.segue.overviewController.openSettings, sender: self)
performSegue(withIdentifier: R.segue.overviewController.openSettings, sender: self)

// And then prepare it:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let typedInfo = R.segue.overviewController.openSettings(segue: segue) {
typedInfo.segue.animationType = .LockAnimation
typedInfo.destinationViewController.lockSettings = true
Expand All @@ -154,7 +153,7 @@ override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
```swift
let nameOfNib = "CustomView"
let customViewNib = UINib(nibName: "CustomView", bundle: nil)
let rootViews = customViewNib.instantiateWithOwner(nil, options: nil)
let rootViews = customViewNib.instantiate(withOwner: nil, options: nil)
let customView = rootViews[0] as? CustomView

let viewControllerWithNib = CustomViewController(nibName: "CustomView", bundle: nil)
Expand All @@ -178,10 +177,10 @@ class FaqAnswerController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
let textCellNib = UINib(nibName: "TextCell", bundle: nil)
tableView.registerNib(textCellNib, forCellReuseIdentifier: "TextCellIdentifier")
tableView.register(textCellNib, forCellReuseIdentifier: "TextCellIdentifier")
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let textCell = tableView.dequeueReusableCellWithIdentifier("TextCellIdentifier", forIndexPath: indexPath) as! TextCell
textCell.mainLabel.text = "Hello World"
return textCell
Expand All @@ -194,10 +193,10 @@ class FaqAnswerController: UITableViewController {
class FaqAnswerController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.registerNib(R.nib.textCell)
tableView.register(R.nib.textCell)
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let textCell = tableView.dequeueReusableCellWithIdentifier(R.nib.textCell.identifier, forIndexPath: indexPath)!
textCell.mainLabel.text = "Hello World"
return textCell
Expand All @@ -213,10 +212,10 @@ class RecentsController: UICollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()
let talkCellNib = UINib(nibName: "TalkCell", bundle: nil)
collectionView?.registerNib(talkCellNib, forCellWithReuseIdentifier: "TalkCellIdentifier")
collectionView?.register(talkCellNib, forCellWithReuseIdentifier: "TalkCellIdentifier")
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("TalkCellIdentifier", forIndexPath: indexPath) as! TalkCell
cell.configureCell("Item \(indexPath.item)")
return cell
Expand All @@ -229,10 +228,10 @@ class RecentsController: UICollectionViewController {
class RecentsController: UICollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.registerNib(R.nib.talkCell)
collectionView?.register(R.nib.talkCell)
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(R.reuseIdentifier.talkCell, forIndexPath: indexPath)!
cell.configureCell("Item \(indexPath.item)")
return cell
Expand Down

0 comments on commit 3d1654e

Please sign in to comment.