I want to be able to move an image from left to right.
Not specific to Swift, but good to know for working with GitHub.
Create a new repository on Github. Give it the same name as the project you're working on in Xcode. When you create a new repository, it gives you a link... git@github.com:YOUR_GITHUB_USERNAME/FILENAME.git Create an Xcode project with the same name. In your terminal, us $ cd to navigate into that folder. You can check that you're in it with $ pwd. Once you know you're in the right folder use $ git init . to add a file. Then add the link from Github. $ git remote add origin git@github.com:YOUR_GITHUB_USERNAME/github_checkpoint.git Now verify that it set the remote server correctly... $ git remote -v This should show you a (fetch) and (push) with the origin. Now you can push and pull away! Most apps are built on tableviews, so it's an important concept to grasp.
Pull a tableview into your storyboard. Not a tableViewController mind you, that creates a new view controller. We want to add a table to our existing controller. Create your outlet... @IBOutlet weak var tableView: UITableView! In your class: ViewController, you need to add UITableViewDelegate, UITableViewDataSource Then in the viewDidLoad() we need to set them up... tableView.delegate = self tableView.dataSource = self Create an array to populate our table... var items: [String] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] We need to create two separate tableViews to make this work, cellForIndexRow and numberOfRowsInSection. The cells tell us what is going to be put in each cell. The rows tell us how many rows there will be in our table. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // creates the tableviewcell var cell = UITableViewCell() //put's the strings we created earlier into a label cell.textLabel?.text = items[indexPath.row] // brings up the tableview cell return cell } Then we need to call up the number of Rows that will be in our table... func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return items.count //returns the number of items in our array we first created } And there you have a basic table. I have an array...
var animals = ["cat" ,"dog" ,"horse", "mouse" ,"pig"] I would like to pull out the last item to work with. My array is always changing, so I would like to specify the last one instead of an actual number. This would occur on something such as a Facebook feed where the last comment is updated constantly. First I want the number of items in my array animals.count This gives me 4, since in computer world counting starts at zero. However my number is always changing, so to pull up the last one added I use... animals[animals.count - 1] This covers for the fact that we started counting at zero. Here's an example of how I use it to change the color of the last comment on a Instagram clone I'm working on. My array in this instance is a mediaItem that I created earlier. if index == (self.mediaItem.comments.count - 1) { // ADD CODE TO MAKE THE WHOLE COMMENT ORANGE let commentRange = NSMakeRange(0, (baseString as NSString).length) oneCommentString.addAttribute(NSForegroundColorAttributeName, value: UIColor.orangeColor(), range: commentRange) } Pretty nifty! |
Girl loves her some Swift. ArchivesCategories |