Skip to content

Commit

Permalink
update for 6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mattneub committed Oct 2, 2014
1 parent b913a38 commit 9b9e8f8
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RootViewController : UITableViewController {
cell.textLabel!.text = "The author of this book, who would rather be out dirt biking"

// shrink apparent size of image
let im = UIImage(named:"moi.png")
let im = UIImage(named:"moi.png")!
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36,36), true, 0.0)
im.drawInRect(CGRectMake(0,0,36,36))
let im2 = UIGraphicsGetImageFromCurrentImageContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class RootViewController : UITableViewController {

let iv = cell.viewWithTag(1) as UIImageView
// shrink apparent size of image
let im = UIImage(named:"moi.png")
let im = UIImage(named:"moi.png")!
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36,36), true, 0.0)
im.drawInRect(CGRectMake(0,0,36,36))
let im2 = UIGraphicsGetImageFromCurrentImageContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RootViewController : UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerNib(UINib(nibName:"MyCell", bundle:nil), forCellReuseIdentifier: "Cell") // *
self.tableView.registerNib(UINib(nibName:"MyCell", bundle:nil)!, forCellReuseIdentifier: "Cell") // *
self.tableView.separatorInset = UIEdgeInsetsMake(0, 15, 0, 15)
// self.tableView.rowHeight = 58 // *
}
Expand All @@ -29,7 +29,7 @@ class RootViewController : UITableViewController {

let iv = cell.viewWithTag(1) as UIImageView
// shrink apparent size of image
let im = UIImage(named:"moi.png")
let im = UIImage(named:"moi.png")!
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36,36), true, 0.0)
im.drawInRect(CGRectMake(0,0,36,36))
let im2 = UIGraphicsGetImageFromCurrentImageContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RootViewController : UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerNib(UINib(nibName:"MyCell", bundle:nil), forCellReuseIdentifier: "Cell") // *
self.tableView.registerNib(UINib(nibName:"MyCell", bundle:nil)!, forCellReuseIdentifier: "Cell") // *
self.tableView.separatorInset = UIEdgeInsetsMake(0, 15, 0, 15)
// self.tableView.rowHeight = 58 // *
}
Expand All @@ -29,7 +29,7 @@ class RootViewController : UITableViewController {

let iv = cell.theImageView // *
// shrink apparent size of image
let im = UIImage(named:"moi.png")
let im = UIImage(named:"moi.png")!
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36,36), true, 0.0)
im.drawInRect(CGRectMake(0,0,36,36))
let im2 = UIGraphicsGetImageFromCurrentImageContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RootViewController : UITableViewController {

let iv = cell.theImageView // *
// shrink apparent size of image
let im = UIImage(named:"moi.png")
let im = UIImage(named:"moi.png")!
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36,36), true, 0.0)
im.drawInRect(CGRectMake(0,0,36,36))
let im2 = UIGraphicsGetImageFromCurrentImageContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RootViewController : UITableViewController {

let iv = cell.theImageView
// shrink apparent size of image
let im = UIImage(named:"moi.png")
let im = UIImage(named:"moi.png")!
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36,36), true, 0.0)
im.drawInRect(CGRectMake(0,0,36,36))
let im2 = UIGraphicsGetImageFromCurrentImageContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RootViewController : UITableViewController {
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class RootViewController : UITableViewController {
super.viewDidLoad()

let url = NSBundle.mainBundle().URLForResource("trivia", withExtension: "txt")
let s = String.stringWithContentsOfURL(url!, encoding: NSUTF8StringEncoding, error: nil)
var arr = s!.componentsSeparatedByString("\n")
let s = String(contentsOfURL:url!, encoding: NSUTF8StringEncoding, error: nil)!
var arr = s.componentsSeparatedByString("\n")
arr.removeLast()
self.trivia = arr

self.tableView.registerNib(UINib(nibName: "Cell", bundle: nil), forCellReuseIdentifier: "Cell")
self.tableView.registerNib(UINib(nibName: "Cell", bundle: nil)!, forCellReuseIdentifier: "Cell")
self.tableView.rowHeight = UITableViewAutomaticDimension // not actually necessary
self.tableView.estimatedRowHeight = 40 // turn on automatic cell variable sizing!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RootViewController : UITableViewController {

let ud = NSUserDefaults.standardUserDefaults()
let setting = tv.cellForRowAtIndexPath(indexPath)!.textLabel!.text
let header = self.tableView(tv, titleForHeaderInSection:indexPath.section)
let header = self.tableView(tv, titleForHeaderInSection:indexPath.section)!
ud.setValue(setting, forKey:header)

NSLog("%@", "about to reload!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RootViewController : UITableViewController, UISearchBarDelegate {
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ extension SearchResultsController : UISearchResultsUpdating {
self.filteredData = self.originalData.filter {
s in
let options = NSStringCompareOptions.CaseInsensitiveSearch
let found = (s as NSString).rangeOfString(target, options: options).length
return (found != 0)
let found = s.rangeOfString(target, options: options)
return (found != nil)
}
self.tableView.reloadData()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RootViewController : UITableViewController, UISearchBarDelegate {
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ extension SearchResultsController : UISearchResultsUpdating {
if searchController.searchBar.selectedScopeButtonIndex == 0 {
options = options | .AnchoredSearch
}
let found = (s as NSString).rangeOfString(target, options: options).length
return (found != 0)
let found = s.rangeOfString(target, options: options)
return (found != nil)
}
self.tableView.reloadData()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RootViewController : UITableViewController, UISearchBarDelegate {
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down Expand Up @@ -158,8 +158,8 @@ extension RootViewController : UISearchResultsUpdating {
let newsec = sec.filter {
s in
let options = NSStringCompareOptions.CaseInsensitiveSearch
let found = (s as NSString).rangeOfString(target, options: options).length
return (found != 0)
let found = s.rangeOfString(target, options: options)
return (found != nil)
}
return newsec
}.filter {$0.count > 0} // is Swift cool or what?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RootViewController : UITableViewController {
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RootViewController : UITableViewController {
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RootViewController : UITableViewController, UITextFieldDelegate {
self.numbers = ["(123) 456-7890"]
self.tableView.allowsSelection = false

self.tableView.registerNib(UINib(nibName: "MyCell", bundle: nil), forCellReuseIdentifier: "Cell")
self.tableView.registerNib(UINib(nibName: "MyCell", bundle: nil)!, forCellReuseIdentifier: "Cell")
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RootViewController : UITableViewController {
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RootViewController : UITableViewController {
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RootViewController : UITableViewController {
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down Expand Up @@ -101,7 +101,7 @@ class RootViewController : UITableViewController {
// menu handling ==========

override func tableView(tableView: UITableView, shouldShowMenuForRowAtIndexPath indexPath: NSIndexPath) -> Bool {
let mi = UIMenuItem(title: "Abbrev", action: "abbrev:")
let mi = UIMenuItem(title: "Abbrev", action: "abbrev:")!
UIMenuController.sharedMenuController().menuItems = [mi]
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ViewController : UICollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()

let layout = self.collectionView.collectionViewLayout as UICollectionViewFlowLayout
let layout = self.collectionView!.collectionViewLayout as UICollectionViewFlowLayout
layout.itemSize = CGSizeMake(150,50)

let v = UIView()
Expand All @@ -19,11 +19,11 @@ class ViewController : UICollectionViewController {
return true
}

override func numberOfSectionsInCollectionView(collectionView: UICollectionView!) -> Int {
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}

override func collectionView(collectionView: UICollectionView!, numberOfItemsInSection section: Int) -> Int {
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 20
}

Expand All @@ -41,7 +41,7 @@ class ViewController : UICollectionViewController {
the content view and its contents are on top of that
*/

override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell",
forIndexPath:indexPath) as UICollectionViewCell
if cell.backgroundView == nil { // brand new cell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ViewController : UICollectionViewController {
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ViewController : UICollectionViewController, UICollectionViewDelegateFlowL
var sectionData = [[String]]()
lazy var modelCell : Cell = { // load lazily from nib
() -> Cell in
let arr = UINib(nibName:"Cell", bundle:nil).instantiateWithOwner(nil, options:nil)
let arr = UINib(nibName:"Cell", bundle:nil)!.instantiateWithOwner(nil, options:nil)
return arr[0] as Cell
}()

Expand All @@ -24,7 +24,7 @@ class ViewController : UICollectionViewController, UICollectionViewDelegateFlowL
}

override func viewDidLoad() {
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)
let s = NSString(contentsOfFile: NSBundle.mainBundle().pathForResource("states", ofType: "txt")!, encoding: NSUTF8StringEncoding, error: nil)!
let states = s.componentsSeparatedByString("\n") as [String]
var previous = ""
for aState in states {
Expand Down Expand Up @@ -67,6 +67,8 @@ class ViewController : UICollectionViewController, UICollectionViewDelegateFlowL
func setUpFlowLayout(flow:UICollectionViewFlowLayout) {
flow.headerReferenceSize = CGSizeMake(50,50) // larger - we will place label within this
flow.sectionInset = UIEdgeInsetsMake(0, 10, 10, 10) // looks nicer
// uncomment to crash
// flow.estimatedItemSize = CGSizeMake(100,30)
}

override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
Expand Down Expand Up @@ -129,7 +131,7 @@ class ViewController : UICollectionViewController, UICollectionViewDelegateFlowL
shadow.shadowBlurRadius = 4
let check2 =
NSAttributedString(string:"\u{2714}", attributes:[
NSFontAttributeName: UIFont(name:"ZapfDingbatsITC", size:24),
NSFontAttributeName: UIFont(name:"ZapfDingbatsITC", size:24)!,
NSForegroundColorAttributeName: UIColor.greenColor(),
NSStrokeColorAttributeName: UIColor.redColor(),
NSStrokeWidthAttributeName: -4,
Expand Down Expand Up @@ -168,8 +170,11 @@ class ViewController : UICollectionViewController, UICollectionViewDelegateFlowL
// ...until I introduced the "container" view
// systemLayoutSize works on the container view but not on the cell itself in iOS 8
// (perhaps because the nib lacks a contentView)
// Oooh, fixed (6.1)!
self.modelCell.lab.text = self.sectionData[indexPath.section][indexPath.row]
var sz = self.modelCell.container.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
//the "container" workaround is no longer needed
//var sz = self.modelCell.container.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
var sz = self.modelCell.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
sz.width = ceil(sz.width); sz.height = ceil(sz.height)
return sz
}
Expand Down Expand Up @@ -232,7 +237,7 @@ class ViewController : UICollectionViewController, UICollectionViewDelegateFlowL
// exactly as for table views

override func collectionView(collectionView: UICollectionView, shouldShowMenuForItemAtIndexPath indexPath: NSIndexPath) -> Bool {
let mi = UIMenuItem(title:"Capital", action:"capital:")
let mi = UIMenuItem(title:"Capital", action:"capital:")!
UIMenuController.sharedMenuController().menuItems = [mi]
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MyFlowLayout : UICollectionViewFlowLayout {
UIApplication.sharedApplication().beginIgnoringInteractionEvents()

let visworld = self.collectionView!.bounds
let anim = MyDynamicAnimator(collectionViewLayout:self)
let anim = MyDynamicAnimator(collectionViewLayout:self)!
self.animator = anim

let atts = self.layoutAttributesForElementsInRect(visworld)
Expand All @@ -93,12 +93,12 @@ class MyFlowLayout : UICollectionViewFlowLayout {
coll.collisionDelegate = self
anim.addBehavior(coll)

let beh = UIDynamicItemBehavior(items:atts)
let beh = UIDynamicItemBehavior(items:atts)!
beh.elasticity = 0.8
beh.friction = 0.1
anim.addBehavior(beh)

let grav = UIGravityBehavior(items:atts)
let grav = UIGravityBehavior(items:atts)!
grav.magnitude = 0.8
grav.action = {
let atts = self.animator.itemsInRect(visworld)
Expand Down
Loading

0 comments on commit 9b9e8f8

Please sign in to comment.