cs193p – Lecture #1 – Course Overview and Introduction to iOS, Xcode, and Swift

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

The cs193p course has started a new edition #Spring2016 featuring iOS 9.

Like every year lecture #1 is an general introduction of the course with an overview about iOS, MVC and a life demonstration of creating a calculator app.

The lecture as well as its slides are available via iTunes named “Course Overview and Introduction to iOS, Xcode, and Swift”. The code for the demo is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Smashtag 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 Smashtag code with Swift 1.2. are quite extensive:

  • countElements() is now called count()
  • as needs to be replaced with as!
  • reduce() requires the combine parameter named explicitly
  • same with custom methods, its now quite strict …
  • let is now more restrictive, some parameters have to be changed to var (it might be I went a little bit over board here)
  • NSString is no String any more and needs to be cast explicitly
  • if a parameter is set within a closure of the init method, set a default value outside

The updated code is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

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