cs193p – Calculator Update Swift 1.2

Please note, this blog entry is from a previous course. You might want to check out the current one.

To run the calculator code with Swift 1.2. tiny adjustments are necessary:

  • countElements() is now called count()
  • as needs to be replaced with as!

… and I forgot to address the second operator in assignment #2 extra task #1.

The updated code is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #5 Assignment #5 Step #5 – The Configuration

Please note, this blog entry is from a previous course. You might want to check out the current one.

For the configuration – the settings of the game – create a new class which will handle the communication with the user defaults. Most of the variables stored in the settings are optional, as a way when to use default values.

The columns and the rows setting hold the dimensions of the level “one” of the brick wall:

    struct Const {
        static let ColumnsKey = "Settings.Columns"
        static let RowsKey = "Settings.Rows"
    }

    let defaults = NSUserDefaults.standardUserDefaults()

    var columns: Int? {
        get { return defaults.objectForKey(Const.ColumnsKey) as? Int}
        set { defaults.setObject(newValue, forKey: Const.ColumnsKey) }
    }

    var rows: Int? {
        get { return defaults.objectForKey(Const.RowsKey) as? Int}
        set { defaults.setObject(newValue, forKey: Const.RowsKey) }
    }

Continue reading “cs193p – Project #5 Assignment #5 Step #5 – The Configuration”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #5 Assignment #5 Step #4 – The Alert

Please note, this blog entry is from a previous course. You might want to check out the current one.

That’s a quick one. In the last completion block of the destroy animation check if there are any bricks left:

    private func destroyBrickAtIndex(index: Int) {
        ...
                    ...
                    UIView.animateWithDuration(1.0, animations: {
                        ...
                        }, completion: { (success) -> Void in
                            ...
                            ...
                            if self.bricks.count == 0 {
                                self.levelFinished()
                            }
                    })
            ...
    }

Continue reading “cs193p – Project #5 Assignment #5 Step #4 – The Alert”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #5 Assignment #5 Step #3 – The Bricks

Please note, this blog entry is from a previous course. You might want to check out the current one.

A new structure provides two sets of information – the view of the brick and its relative frame information (without information about the current device information). Store this structure for each brick in a dictionary:

    var bricks = [Int:Brick]()
    
    struct Brick {
        var relativeFrame: CGRect
        var view: UIView
    }

Continue reading “cs193p – Project #5 Assignment #5 Step #3 – The Bricks”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #5 Assignment #5 Step #2 – The Paddle

Please note, this blog entry is from a previous course. You might want to check out the current one.

Create the paddle lazily. Place it outside (just a little bit) of the game view – which perhaps a bad way to know if it has been created recently. … and make it nice and colorful, with rounded corners etc …

    struct Constants {
        static let PaddleSize = CGSize(width: 80.0, height: 20.0)
        static let PaddleCornerRadius: CGFloat = 5.0
        static let PaddleColor = UIColor.greenColor()
    }

    lazy var paddle: UIView = {
        let paddle = UIView(frame: CGRect(origin: CGPoint(x: -1, y: -1), size: Constants.PaddleSize))
        paddle.backgroundColor = Constants.PaddleColor
        paddle.layer.cornerRadius = Constants.PaddleCornerRadius
        paddle.layer.borderColor = UIColor.blackColor().CGColor
        paddle.layer.borderWidth = 2.0
        paddle.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
        paddle.layer.shadowOpacity = 0.5
        
        self.gameView.addSubview(paddle)
        
        return paddle
    }()

Continue reading “cs193p – Project #5 Assignment #5 Step #2 – The Paddle”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #5 Assignment #5 Step #1 – The Ball

Please note, this blog entry is from a previous course. You might want to check out the current one.

Task #1

Create a straightforward Breakout game using Dynamic Animator. See the image in the Screen Shots section below to get a general idea of the game, but your UI should not look exactly like the Screen Shot. Creativity is encouraged and will be rewarded.

Hint #1

This assignment is intentionally vague about the feature set of your game to make room for you to show us some creativity. …

Continue reading “cs193p – Project #5 Assignment #5 Step #1 – The Ball”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #4 Assignment #4 Extra Task #6

Please note, this blog entry is from a previous course. You might want to check out the current one.

Add some UI which displays a new view controller showing a UICollectionView of the first image (or all the images if you want) in all the Tweets that match the search. When a user clicks on an image in this UICollectionView, segue to showing them the Tweet.


Let’s start with the storyboard:

  • Add a collection view controller.
  • Add a segue from the tweet table view controller to the new controller (note: from the controller itself not from one of its elements or table cells) and name the segue.
  • Add a button to the right side of the navigation bar and link it to the unwind method from extra task #3
  • Add a reuse identifier for the collection view cell.
  • Add an image view to the cell (including autolayout constraints).
  • Add an activity indicator on top (including constraints)
  • Finally add a segue from the cell back to the tweets table view controller and name it.

Continue reading “cs193p – Project #4 Assignment #4 Extra Task #6”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail