Beginners Group


#1

For people without programming experience.

Share your struggle, learn from others, post and find resources that can help us further.


#2

I just wanted to let you know you weren’t alone in this endeavor. I will be frequenting this thread. I hope we can help one another out.


#3

@rwdawg2 This group is here for this exact purpose : to help each other . Good luck to you and a happy learning experience.


#4

// ViewController.swift
// Word Magnets
//
// Created by Andrew Gostanian on 10/13/14.
// Copyright © 2014 Andrew J Gostanian Jr. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    
    var wordArray = ["I", "Like", "to", "build", "Computer", "Programs", "but", "I", "am", "struggling", "with", "learning", "the", "code"]
   view.backgroundColor = UIColor.blackColor()
    
    
    for word in wordArray {
        var label = UILabel()
        label.text = word //wordArray[4]
        label.font = UIFont.systemFontOfSize(32)
        label.textColor = UIColor.blueColor()
        
        label.sizeToFit()
        label.center = CGPoint(x:160, y: 240)
        label.backgroundColor = UIColor.whiteColor()
        
        var x = CGFloat(arc4random_uniform(300))
        var y = CGFloat(arc4random_uniform(480))
        label.center = CGPoint(x: x, y: y)
        
        view.addSubview(label)
        
        var panGesture = UIPanGestureRecognizer(target: self, action: Selector("handlePanGesture"))
        label.addGestureRecognizer(panGesture)
        label.userInteractionEnabled = true
    }
}

func handlePanGesture(panGesture: UIPanGestureRecognizer) {
    
    println("pan")
    var translation = panGesture.translationInView(view)
    println("translation")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

// This is crashing


#5

As you need a parameter for your handlePanGesture function you need to add the colon after its Selector name : “handlePanGesture:”


#6

ah @Paradisiak you beat me with 7 min . This was my first error which I KNEW how to do it.

@drewgost you just missed “:” after (“handlePanGesture”))


#7

It’s a clear sign that you have already made a lot of progress :+1:


#8

dont t think so because I STILL don’t know how to take input from a user text field . Please help @Paradisiak
var userInputTextString = ""
var optionalInt = userInputTextString.toInt()

    if let number = userInputTextString.toInt() {
        println(" Optional binding nr: \(number)")
        
    } else {
        println(" Optional binding invalid input: \(userInputTextString)")
    }

#9

I dont understand your 2 var definitions :
var userInputTextString = ""
var optionalInt = userInputTextString.toInt()

the first should be an outlet of your storyboard textfield like :

@IBOutlet weak var userInputTextString: UITextField!

and you dont need the second one because it is already the role of your number var.

After that your code needs to take the text property of your user variable :

if let number = userInputTextString.text.toInt() {
    println(" Optional binding nr: \(number)")

} else {
    println(" Optional binding invalid input: \(userInputTextString.text)")
}

You can see a example of user text interaction in the Day 8 solutions (guess a number) where we take the input of the guessing number : the link


#10

Thanks for the fix. It no longer crashes


#11

All I have not used a Mac since college and have been a PC guy for a very long time…one of the things that has frustrated me is the fact that the scrolling on the track pad of the Mac behaves differently than the scrolling on the mouse. I have since found a solution that allows you to set the behavior of the mouse scroll wheel and the track pad differently. I am using it now and it works like a champ! Just thought I would share.
https://pilotmoon.com/scrollreverser/


#12

I am a bit of a new guy when it comes to development so a couple of approach questions for some of you seasoned vets out there…What questions do you typically ask yourself to determine that:

  1. Something needs to be a function (outside of a class)? I guess one is does this function need to be used within other classes (assuming that putting the function outside of a set of classes allows it to be used in those classes). I am sure there are other questions/considerations.
  2. Something needs to be a method (inside the class)? Maybe one is that this method needs to be constrained to this class and should not be exposed to other classes? I am sure there are other questions/considerations.
    Thanks for your help in advance!

#13

How can I make a tableView working ??? and how to add 3 parameters on every cell? @Paradisiak, @PaulSolt

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var tableView: UITableView!
    var items = ["1", "2", "3"]

override func viewDidLoad() {
    super.viewDidLoad()
    
    self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}


func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
    return self.items.count;
}

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
    
    cell.textLabel.description = self.items[indexPath.row]
    
    return cell
}

func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
    println("You selected cell #\(indexPath.row)!")
}

}


#14

I’ll discuss TableViews next week.


#15

Wow didn’t see this section. Im totally new to programming and I do find it hard to figure out what is added to each part before or after the code to “connect it” to another method. I guess it will come with time and practice.


#16

Hello, I’ve got a very strong understanding of all the individual meanings I’ve learned so far of each code itself but I’m having a hard time taking my knowledge of everything and piecing some together into simple lines of code and how they work as a whole. Any techniques or examples that will help me understand how to piece it all together or will it all make sense later in the videos as I’m only on Day 7. Thanks :smiley: .


#17

I am having problems with my IO6 simulator. When i press run/play button it works but is a little slow (thinks about it). When i update anything click stop it hangs / nothing happens and i have to force quit Xcode and restart. Any ideas what to do to rectify this? it’s IOS Simulator Iphone6/IOS 8.3 (12F69) and my Xcode is Version 6.3.2 (6D2105)


#18

It appears my simulator was very out of date. If you face the same as me, go to Xcode / Preferences then select the Downloads tab and make sure your IOS simulator is up to date. Updating from 6.3 up to 8.2 now…


#19

Although my Xcode is still hanging even with IOS simulator updated… :frowning:


#20

@felineuk Have you had any luck with restarting your Mac, Xcode, and trying again?

What kind of Mac are you using?