100 Days of Code: 10 Days In

This is my !Shiny New…for a limited time only discussion of progress in coding work. I am inspired to begin this as a dedicated section because of the sheer volume of my total time spent coding and the many diverse tasks and learnings that takes in a given week. Also, this week I joined the Habitica Aspiring Blacksmiths group and promptly jumped into #100daysofcode. Of course I can do 100 days of code, since I’ve been doing a little every.single.day. However, I have many coding activities, and I really need a place outside of the GitHub log where I can track how my thinking changes over time. Hopefully, I will learn something along the way that is helpful to someone else.

Okay, so I started this game on July 3. In 10 Days, I have:
+ signed up on a crap-ton of websites to do different things
+ joined Hacker Rank and went from algorithm rank 508575 to 150588
+ created two bootstrap websites on Code Pen as part of Free Code Camp basic development projects. They are very basic, but working: Tribute to Wendell Berry and Personal Portfolio sample page
+ read 6 chapters of Clean Code by Robert Martin – it has given me some food for thought although a few concepts are out of my vocabulary, so I will have to return to them.
+ created a python language twitter bot – which you can check out at public GitHub repo for the Pink Fairy Bot, the @PinkFairyBook twitter profile, or interact with it using the hashtag “#PinkFairyBook” on twitter.

While I feel as though I have done things, most of it has been superficial. I enjoy solving algorithms, and I am gaining some new knowledge of basic underlying language for Swift and javascript – things that I have even used without understanding before. However, I prefer the pressure? challenge? excitement? something that comes from actually solving problems that will help people. I am going to spend some time tomorrow planning out the next 10 days so that I will make forward progress on real projects in addition to the challenges I’ve joined.

Waiting on a Simulator

I’ve been working in Xcode developing little applications to learn iOS Programming and making other little applications that help me. While in development, I use the simulator a ton to check my work. It always takes forever.

Perhaps I just need more RAM. I’m not getting more RAM anytime soon…this 2011 macbook is gonna have to keep cutting it. In the meantime, I came up with a list of things to do while waiting for the Xcode Simulator to load.

Things to do while waiting for the simulator
– refill coffee and make a snack
– post a picture of _______ on Instagram. Hell, post 2 or 3.
– water the plants
– solve Sudoku puzzle (I use Sudoku2 by Finger Arts)
– save some Monsters (I still play Gemmed)
– play with the dog
– update todo list (I use Dave Seah’s mini ETP – link below)
– work on plans to take over the world
– start a load of laundry
– sweep the floor
– build a rocket
– make a cup of tea
– clip the cat’s nails

Over time, I have also learned that there are things to not do.
Things NOT to do while waiting for the simulator
– open Twitter to “catch up”
– open Facebook to “see what friends are up to”
– call anyone over to see how cool your app looks
– start reading a book

I recommend reading about the theory of the ETP on Dave’s blog. I’ve been using the mini-ETP for over a year, but I started with printing off the full size ETP to try it out. I’m absolutely attached to the A5 size, the thick paper, and the aesthetic of the spiral bound version that I get on Amazon. Each notebook lasts me about 3-4 months, depending on how much weekend planning I do.

iOS App Development: Sharing data across tabs

Just recently, I shared a method to pass data to multiple tabs. I got some feedback that it was helpful (aside: I did not even know anyone read this blog, so that was a real boost.). However, that method really is only useful for static “presentation” of data, and it gets a bit clunky with multiple view controllers.

Whaddya mean by “clunky”?
Allow me to demonstrate. The method was basically, send all of the view controllers within the tab view controller the data at the time of the first segue.

For the two view controllers that I showed, the prepare for segue from the root view controller (with the two big buttons) looked like:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "toTabSegue" {
            let tabBarC = segue.destination as! UITabBarController
            let detailVC1 = tabBarC.viewControllers?[0] as! FirstViewController
                detailVC1.theColor = theColor
                detailVC1.theEx = myex[theColor]
            let detailVC2 = tabBarC.viewControllers?[1] as! SecondViewController
                detailVC2.theColor = theColor
                detailVC2.theFlower = myflower[theColor]
}

Let’s imagine for a second that we have gasp five view controllers. The code is then at least nine lines longer (assuming that each of our three new controllers has two variables), and we have to keep track of all of the variables in the view controllers. Um, no thank you?

What if I create a dataModel instead and call it from the view controller?
You can do that. I tested that as well, creating a separate dataModel and using another tabbed view controller, creatively named “ThirdViewController” to test the segue.

In this case, create a subclass of NSObject that is called DataModel and put some code in there to find some value. I made up a useless dictionary for this example. You will then make the view controller using this data a delegate.

@objc protocol DataModelDelegate: class {
    @objc optional func didRecieveDataUpdate(data: String)
    @objc optional func ex2for(thisex2: String)

}

class theDataModel: NSObject {
    weak var delegate: DataModelDelegate?
    func getEx2(color:String) {
        let myex2 : [String : String] = [
            "blue" : "You Picked Blue",
            "red" : "You Picked Red"
        ]
        let thisex2 = myex2[color]!
        delegate?.ex2for!(thisex2: thisex2)
    }
}

We need to make sure that the dataModel knows what color button was pushed in our prepare for segue in the root view controller, so we add:

let detailVC3 = tabBarC.viewControllers?[2] as! ThirdViewController
detailVC3.theColor = theColor

Notice that we only need to let our “ThirdViewController” aware of the color and we do not need to load the string that will come from our data model.

We then set the ThirdViewController as a delegate and call on the data model in the view controller. NOTE that we would do the same thing for all of our view controllers if we were really using this method. I’m just demonstrating here.

class ThirdViewController: UIViewController, DataModelDelegate {

    // MARK: - Properties
    private let dataModel = theDataModel()
    var theColor: String? // empty string
    @IBOutlet weak var anotherLabel: myLabel!

    // MARK: - LifeCycle

    override func viewDidLoad() {
        super.viewDidLoad()
        // go call our fancy datamodel
        dataModel.delegate = self
        dataModel.getEx2(color: theColor!)
    }

    // MARK: - DataModelDelegate Methods
    func ex2for(thisex2: String){
        anotherLabel.text = thisex2
    }
}

What if I want to be able to change things in one tab and know about them in another? What if I don’t want to deal with delegates and all that jazz?
You ask good questions. I was basically ready to throw my macbook while trying to answer these as well because folks who have the answers are so far advanced that their explanations don’t even make sense to someone just starting out (or maybe just me). In any case, I found the solution to be to pass the model through the tab bar controller, well, a subclass of tab bar controller. Since we are adding a bunch of stuff, I’ve broken it down into steps, but feel free to just look at the code and work from there.

  1. Create a new model that calculates everything we want to do. This is a very simple file that subclasses NSObject and essentially repeats the data fetching that we were doing within the RootViewController. Create a new file of CocoaTouchClass that subclasses NSObject. I called it “ColorModel”.
class ColorModel: NSObject {

    var color:String = ""
    var example:String = ""
    var flower:String = ""
    
   func myExample() -> String{//return correct example
        let myex : [String : String] = [
        "blue" : "sky",
        "red" : "fire",
        "" : "none"
        ]
        return myex[color]!
    }
    func myFlower() -> String{
        let myflower : [String : String] = [
        "blue" : "violet",
        "red" : "rose",
        "" : "none"
    ]
        return myflower[color]!
    }
}
  1. Create a subclass of UITabBarController and update related references in the storyboard and also in the RootViewController.
    Create a new file of CocoaTouchClass that subclasses UITabBarController. I called it “ColorTabController”. This is also a very simple file.
class ColorTabController: UITabBarController {

    var myColor = ColorModel()

}

Go to the storyboard and ensure that UITabBarController is changed to your new subclass.

Change the initial header in prepare for segue in the root view controller to now go to ColorTabController instead of generic UITabBarController:

 let tabBarC = segue.destination as! ColorTabController //change
  1. Deal with passing this model in the RootViewController
    We need to make sure that the dataModel knows what color button was pushed in our prepare for segue in the root view controller, so we add:
 tabBarC.myColor.color = theColor

Notice that we only need this one line to tell the ColorModel() instantiated in the ColorTabController that color is now “theColor”.

  1. Set up our new view controllers.
    Let’s create two more view controllers that will be part of our tab. You can do this on the storyboard by creating view controllers and then CTRL+drag from the TabBarController to your new view controllers. When the pop up appears, select “Relationship/view controllers” and it will be added as a tab. I added several labels to FourthViewController and put them in stackviews to make them kinda pretty. You can get by with just 3 labels for testing. I added two labels and a button to FifthViewController.

Then, create new subclasses of UIViewController for what is now FourthViewController and FifthViewController. Connect the outlets for the labels and actions for our new button.

  1. Add code in our new view controllers to update references. For both view controllers, we need to add a property to reference the ColorModel(), so var myColor = ColorModel() . We also need to set that the value of this property is a reference to the colormodel in our tabbarcontroller. We do this by adding a reference in ViewDidLoad().
let tbvc = self.tabBarController  as! ColorTabController
        myColor = tbvc.myColor

For each item that we are displaying, we can set up that text in ViewWillLoad().

At this point, FourthViewController.swift should look something like:

class FourthViewController: UIViewController {

    // MARK: - Properties
    var myColor = ColorModel()

    @IBOutlet weak var colorLabel: UILabel!
    @IBOutlet weak var exampleLabel: UILabel!
    @IBOutlet weak var flowerLabel: UILabel!

    // MARK: - LifeCycle

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        // set up the labels
        colorLabel.text = myColor.color
        exampleLabel.text = myColor.myExample()
        flowerLabel.text = myColor.myFlower()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // refer to the tab bar controller where the data are:
        let tbvc = self.tabBarController  as! ColorTabController
        myColor = tbvc.myColor
  }
}

And FifthViewController.swift should look something like:

class FifthViewController: UIViewController {

    // MARK: - Properties
    var myColor = ColorModel()

    @IBOutlet weak var oldColorLabel: UILabel!
    @IBOutlet weak var newColorLabel: UILabel!

    // MARK: - LifeCycle

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        // set up the labels
        oldColorLabel.text = "Color is: " + myColor.color
        newColorLabel.text = "?"

    }

    override func viewDidLoad() {
        super.viewDidLoad()
       // refer to the tab bar controller where the data are:
        let tbvc = self.tabBarController  as! ColorTabController
        myColor = tbvc.myColor
    }

    // Add a button to make a change to the color
    
    @IBAction func changeColorButtonTapped(_ sender: UIButton) {

        switch myColor.color {
        case "blue":  // it was the blue button
            myColor.color = "red"
            print("It was Blue. Change to Red")
        case "red":  // it was the red button
            myColor.color = "blue"
            print("It was Red. Change to Blue")
        default:
            print("Default")
        }

        newColorLabel.text = "Now Color is: " + myColor.color
    }

}

Now, if you run it, changes in FifthViewController will impact FourthViewController. Note that they do not update any of the others. That is because Fourth and Fifth ViewControllers share a reference to a single model where First and Second have no model and Third copies the model.

Tab App in Action

I’ve uploaded the whole updated application including the previous method and the two discussed here as a zip file, if you want to play with it. testTabData_complete.zip

iOS App Development – passing data through multiple tabs

The problem: YTF can’t I pass the data to all of my tabs?

I’ve been working on developing iOS apps for a few months. While I can do some things quite easily, others are still frustratingly out of my grasp. Yesterday, I really wanted to make an app where the same data was presented in multiple ways across tabs. I spent several hours bashing my head against the keyboard bam until I figured out one way to pass the data to all of the tabs. I’m not sure that it is the best way, but it does work, so I am sharing it for other folks who may be struggling in the same way.

One solution: Send all of the data to each tab when preparing to perform the segue. If you are familiar with Swift, it is in this function override func prepare(for segue: UIStoryboardSegue, sender: Any?) {}

Here’s the layout of the basic application: a view controller will present a set of tabbed view controllers depending on which button is pushed.

Storyboard Layout

I’ll go through the Storyboard setup and then the code. The application that we are producing will have a main view where the user can select the Blue or Red button, and then they will see a tabbed view, where one tab shows the color that they selected and an example of something that might be associated with that color and the other tab shows the color that they selected and a flower that might be associated with that color.

Continue reading “iOS App Development – passing data through multiple tabs”

Great Podcasts

I’m constantly talking up all the cool insights and inspiring stories that I hear on podcasts. Some of my friends are finally coming around and asking for my suggestions. Verbally listing a bunch of podcasts (or books, or whatever) becomes taxing to the receiver who is trying to juggle a new information and categorize it for later. So, I have written down this short list of lists.
For you super busy folks – you can do this – I listen to podcasts on double speed while walking to and from the grocery store, running with my dog, cooking dinner, etc. When I’m moving and listening, I get the most value from the podcasts because I do not try to multi-task. Personally, I get no value from podcasts if I’m doing any other mental task, like reading or typing…even browsing instagram. I’ve listed a bunch of podcasts here, but there are others that I have just started trying out and can’t recommend yet. There really are podcasts for every interest. Happy listening!

  1. My absolute favorite podcasts that I’d recommend to everyone
  • Her Money with Jean Chatzky: This weekly podcast runs about 30-40 minutes. Jean targets this podcasts at professional women, but the stories and lessons are really for everyone. The guests are thoughtful and well-spoken; Jean is knowledgeable and keeps the pace. There is good advice in every show. I discovered this one just a few months ago, but it is already a favorite. The Jean Chatzky’s website has tons of information including calculators and guidance on where to get help (see Tools) if you need it.

  • Myths and Legends: This (mostly) weekly podcast runs about 30-40 minutes. Jason Weiser retells myths and legends from folklore in a quick and relatable way. His style is quirky and good humored. The format of the show is consistent – with a fun story and a creature of the week. He often connects the dots between stories, and he sometimes fills in holes in stories. Jason always points out when he has taken creative license with a story or picked one version over another, and he often says why. This is a wonderful diversion. The podcast website includes links to his sources, other places to look up information, and the music used on the show.

  • Side Hustle School: A daily! Short podcast from Chris Guillebeau showcasing what other people are doing for their side hustles. The podcast is usually less than 10 minutes long and describes: what the person is doing, how they are doing it, why they are doing it, and how they are making money. It’s inspiring and well-produced. If you listen on the go, like I do, you will love how organized Chris keeps his show notes – everything is there, nice and connected. Just listen to all of them; if you do fall behind, though, Chris produces a weekly summary show.

  • Radical Candor: This weekly podcast runs about 20 minutes and focuses on helping everyone Care Personally and Challenge Directly. The idea is that we tend to fall into patterns that are not helpful to ourselves, our own bosses, or the people who call us boss because walking the line between being a nice person and being a successful person is challenging. The show was a little bumpy at first but hit its stride after the first few shows. Each show has a theme related to not sucking in the workplace and has little actions that you can do to get better in this area. The hosts use their experiences over years leading teams to bring understanding to how to do something well; sometimes, they bring in external interviewees for another perspective. The show always feels shorter to me than it is.

  • Hidden Brain: This weekly podcast usually runs just under 30 minutes. Shankar Vedantam also appears on short NPR segments in shows like Morning Edition. You can find the podcast on any podcast app, and see both podcast and shorter segments at the Hidden Brain site. This show brings up and discusses one curious human behavior item per episode, and it is almost always something that has broad appeal, like the one about what our Google searches at 2AM mean about us.

  • Dinner Party Download: A weekly podcast (~50 min) that comes out on Friday afternoon (US time) to get you ready for the weekend cocktail parties – if you go to those. The format is perfect: a quick joke, some interesting facts from the week, some history mixed with a new cocktail recipe you could try, a few recommended songs from someone in the music industry, and an interview with someone charming. This one took me a few weeks (years ago) to fall for, but it is a nice bit of audio.

  • Two Guys on your Head: A very short (~7min) weekly podcast from two psychologists/psychiatrists/some kind of head brain doctors (Dr. Art Markman and Dr. Bob Duke). They discuss one issue of human behavior or a question, kind of like Hidden Brain, but with a different style. It’s interesting and short. I listen to this one on NPR One, so I’m not sure if you can get it on regular podcast apps, but it is available at the Two Guys on Your Head site.

  1. Podcasts that I like that I would recommend individually to some people – grouped broadly by topic area:
  • Academic Life / Research:

    • Not So Standard Deviations: This (usually) weekly podcast runs about 30-60 minutes. There is quite a bit of banter, so do not listen to this unless you do data science for work or fun. Hilary and Roger will crack you up with their stories from the pits, but only if you can relate. Ignore all the laughing. The “free advertisement” is really my favorite part, even thought I enjoy these two personalities – at that point in the show, they bring up something that they really like or enjoy which can be anything from an actual thing to a person or an article.
    • The Effort Report: Elizabeth and Roger are fun to listen to, and they have a natural conversation style. Who wouldn’t want to listen to smart people get real about challenges and joys in their work life? That they are talking about academic life, which is largely shrouded in mystery, is all the more fun for me. Sometimes, they bring in other folks to interview – anywhere from senior faculty to postdocs.

    • Everything Hertz This weekly podcast runs about 50 minutes and covers the thoughts of two academic researchers – one in Europe and another in the US on the business of research. Not the money making side, but the “how do we actually get this done, and well” side of it. It’s interesting and nuanced. It may take a few episodes to get into their heads and understand these guys, but then it’s nice to follow along.

  • Politics / US News:

    • Backstory: This weekly podcast changed format from when I first became hooked. The current rendition is still settling in, but it seems to be weekly between 30 and 45 minutes. The hosts are history professors who take issues from our current times and look back over the previous centuries to tell related stories. It is very informative, usually lighthearted, and there is no loss if you skip an episode or hear them out of order.

    • Politically ReActive: This weekly podcast runs about 50-60 minutes. The hosts, W. Kamau Bell and Hari Kondabolu discuss race and politics in America and sometimes have guests come on the show. These guys are both comedians, but this show is usually quite serious. This one is interesting because they bring on people that I don’t hear from in other outlets, usually, and discuss their perspectives on race in a way that I definitely don’t get in real life. I’m not a huge fan of hearing how terrible I am for my whiteness, but the show is worth getting past that part.

    • The Fifth Column: This (usually) weekly podcast runs about 60-75 minutes and features 3 journalists discussing mostly current events. It is a highly opinionated show. I like that the hosts challenge each other and don’t just accept everything said by the colleague/friend as fact or right. They respectfully disagree with each other…perhaps less respectfully disagree with others. I do not always agree with them either, but I appreciate the discussion and different points of view. Sometimes they have guests. NOTE: Of all the podcasts I listen to regularly, this one is the hardest to follow and the one I am most likely to miss key nuance or need to slow down to 1.5 times speed. These guys talk fast and have a base knowledge about current events/people/history that is challenging to me.

    • Katie Couric: This is a weekly show (~40 minutes) where Katie Couric is the host, and she brings in people to interview – interesting people, like Neil deGrasse Tyson, Nate Silver, etc. I remember hearing her name a lot before I found this show, and I think she was a TV news anchor, but I am sure I never saw her on TV. I do enjoy this show, and I always learn something.

  • Life/Stories/Self-betterment:

    • Dear Sugar: This weekly show (~35 min) is hosted by Cheryl Strayed and Steve Almond with beautiful human empathy. Each show is a response to a particular letter or type of letter (anonymous) about a tough question. They read the letter, discuss generalities, usually bring in an expert to interview, and come up with some solid, and kind, advice. The Sugars, as they call themselves are like your favorite aunt or gramma who you could ask anything, but you really could. It is an interesting show for perspective and reflection.

    • Art of Charm: This show is a 5 day a week deal with varying formats by the day of the week. My favorite is Monday which is “Minisode Monday” and just a quick tip (~5 min) that you can take and implement to make your life a little better. The show includes interesting guests and is basically just about a community of people trying to be more awesome and successful, without being obnoxious. I have not joined the AoC or whatever group of fans that is a community. I do still like the show. I do sometimes skip the middle of the week ones, depending on how much time I have.