Guilt and the Ego Trip

Listening to Joseph Goldstein’s Dharma Talks, I found something interesting in relation to guilt. Feelings can be powerful tools for learning. However, guilt can be something that kids and adults get hung up on.

In response to doing something stupid or not nice, I know a young loved one who likes to say “I’m bad.” In his own way, Joseph points out that a person can sometimes get hung up on the story of being bad as opposed to learning from the experience and then moving on.

14:12-ish into his “2015-11-18 Q & A” Dharma Talks, he talks about how we often “justify guilt” in a way that’s not useful. He also points out a technique of “wagging the finger at [guilt]” at 15:07. In other words, he points out that we can notice this unhelpful guilt. It can be identified. We can then change it into “a feeling of wise remorse”, take responsibility and do all of this with understanding.

How to share this concept with a child? My initial thought is to do it with a picture.

BK

Image from BK at https://flic.kr/p/p3yhro

Good luck with your exploration of how to internalize this idea and share this concept with both the young and old.

10% Happier App Is Growing

The 10% Happier: Meditation for Skeptics app, which I originally covered in Meditating on Meditation Mobile Apps, has been growing by leaps and bounds in both value and content.

In the app, Dan Harris continues to ask in-depth and practical questions. However, now there is even more than one meditation expert giving answers. Originally, it was just Joseph Goldstein. He’s a fantastic, wise, and wonderful person to listen to. Now it gets even better with more teachers entering the scene.

The idea is that each meditation teacher will share valuable insights in their own area of specialization. Here’s an example. In the “10% Nicer” section in day 2, Sharon Salzberg and Dan Harris discuss “the why” of meditating on loving-kindness. In other words, why one would start and keep doing the loving-kindness meditation. Together, Dan and Sharon do a great job emphasizing the value in a person’s own personal experience yet also highlighting the importance that science brings. In his own funny way, Dan points out that meditating on loving-kindness makes you nicer and less of an a-hole.

The video interviews are funny. I cannot emphasize this enough. The comical and frank video interviews between Dan Harris and the meditation teachers have been wonderful. The followup guided meditation recordings have been instructive and highly useful. It’s through these you learn by actually experiencing meditation.

Finally, there is the coach. From my own experience, there is no substitute for having a coach that you can send SMS messages to. Having first started meditating decades ago, I have some experience which seems beyond introductory. Yet, I am amazed at some of the new things I have learned and received clarity on.

To learn more, you might want to listen to the OneMind Meditation podcast titled “How To Be 10% Happier with Bestselling Author Dan Harris.” It does a great job covering the journey of the book author which eventually led to the creation of the 10% Happier app. During the recording, credit goes to Dan Harris for pointing out that the company, Change Collective, which built the app is made up of fantastic people. From my personal interactions with them, I would have to agree.

If you’d like to stay up-to-date, you can follow them on twitter at 10% Happier.

If you become hooked like me, please pay it forward and let others know about it. Just imagine if the world was 10% happier or 10% more at ease and loving.

Adventures in Creating iPhone App Store Images

The iPhone app is made and you feel ready to ship. However, you need to get the iPhone app screenshot images into the App Store. When you work at a great place like CARFAX, there are other awesome people who do that quite well.

When doing it on your own, it’s no small feat to make and upload images for your iPhone app that are decent. Sure, one can just grab a screen shot of the app and shove it up there. However, high quality images that evoke an emotional response and reveal interesting parts of your app are best.

Some questions came to mind while I was going through this process:

  • How to create a screen shot of the iPhone app without the status bar?
  • How to have the screenshots look fancy like the Clear or CARFAX mobile apps?

By fancy, I mean have the screenshot surrounded by an iPhone image that is appealing.

Possible Solutions

Let’s quickly go over some possibilities I first ran across. At first glance, placeit.net looked promising. Searching on quorapicapp.net was another possibility. If all else failed, I was going to back to the Ray Wenderlich tutorial to dig up another answer.

placeit.net

placeit.net had real promise. I found out about it from the Ray Wenderlich tutorial. placeit.net has lots of variety in their images. After playing around with it for a long time, I found an image I liked but it didn’t seem like a drop in solution for use in the App Store. Since the variety is fantastic, I may go back to it later for some of my website marketing. For app images though, I eventually decided to start out with something simpler.

picapp.net

This site has a simple and easy to use interface. I like how they have things set up so that you can use PayPal and codes to get your purchase. After playing around, I came up with an image I like. So how many images do I need? Five images for four phone sizes came to twenty images. Each image would cost a few dollars. Hmm. Can one do better?

Ray Wunderlich Tutorial

The tutorial title is How to Make Great App Store Screenshots. It’s a good tutorial. It introduced me to several different options. The last time I saw this tutorial I skipped down pretty quickly to the Photoshop solution so I hadn’t deeply checked out the other options.

Random Thoughts

While going through the tutorial and seeing how much time I spent on all of this, I started having some random thoughts. Thoughts like:

  • Why is this taking so much time?
  • There’s clearly a market for iPhone pictures for the app store.
  • Why do I see typos wherever I look? For example, Screenshot Maker Pro has some serious grammar errors here.

After I got over the typos, I saw that Screenshot Maker Pro looked promising.

Screenshot Maker Pro

I had my doubts due to the typos and from what I saw on the webpage. However, trying out the app had increased my confidence in the solution. After taking a screenshot, making an image, and playing with the settings, I found something I like. However, it’s the wrong size and transparency is on. Apple doesn’t like App Store pictures with the transparency on.

a

So, into an image editor I go. I tried various things including a command line tool called sips.  However, I finally landed on using Acorn. It only cost me about $30. My goal was to just make a 4.7 inch portrait image that’s 750 wide x 1334 tall or vice versa for landscape. After some messing around, I got something that worked. I had to resize the image and then the canvas. I also figured out how to turn off the transparency aka alpha by using the Preview app.

With this new found knowledge, I did the other sizes. For the iPhone 4S, Screenshot Maker Pro didn’t quite work. So, I just uploaded the screenshots themselves. Sometimes you have to know when to say when and move on.

Specific Example For an Image That I Wanted as Landscape:

  • While preserving aspect ratio, I resized the image to a height of 750 pixels. The width ended up being 1089 pixels.
  • I resized the canvas width to the needed 1334 pixels

Time to get rid of the transparency. I turned off the alpha using Mac Preview’s export to PNG with the alpha unchecked.

Image Concerns

  • One of my images showed off the notification that the app sends. However, it also showed the home screen. That violates the following guideline: “Never display the Apple Watch, iPad, iPhone, iPod touch, or Apple TV Home screen or any icon or image that you do not own.” I deleted that image.
  • Looking at my other images, another concern arose. The status bar showed a specific carrier, AT&T.

To hide the status bar for App Store sakes, I found this from a Stack Overflow post:

With that I could temporarily hide the status bar while taking the screen shots. So, I redid all the images.

Acorn Again

Now with the concerns are out of the way, it’s time to reuse Acorn and fix the newly created portrait images with Acorn:

  • Resize image height to 1334 (forces width of 583 to keep same aspect ratio)
  • Resize canvas to 750 width
  • Open in Preview, export as PNG, uncheck “Alpha”

Images Loaded

I loaded the images into iTunes connect. It complained about one of the images, but logging out and logging back in let me put the last image into place.

Now What?

Next step, I need a website. While figuring out how to get a starter webpage up quickly that doesn’t totally stink, Freddy A. Montas mentioned LaunchKit. Glancing at a related TechCrunch article, it seems like LaunchKit might take care of what I need and maybe even the App Store screenshots I just did. So, all of the above might not be needed in the future. That’s OK. I learned a lot and that won’t be my last release into the App Store.

Good luck with your app submission and marketing adventures!

Disclosure: I work for CARFAX as an iOS Software Developer.

RxSwift Moved Swiftly from 1.9 to 2.1

RxSwift 2.1.0 is out! Congrats to kzaher and all the members.

Since things moved fast over the winter holidays in RxSwift, you might see some changes that happened between 2.0.0-beta.4 and 2.0.0 that interest you if you haven’t switched yet. When moving from the latest RxSwift beta to 2.0.0, the 2.0.0-rc.0’s Deprecated section of the Change Log may answer some compilation issues you face.

Straightforward changes were needed for my work. For example, I needed to stick Observable in front of create. As covered in the Change Log:

Deprecates free functions in favor of Observable factory methods

An interesting one involves Variable:

Deprecates Variable implementing ObservableType in favor of asObservable()

Looking at GitHubSignup “UsingVanillaObservables > 1″ and “UsingDriver > 2″ in the RxExample code, I see the answer to my questions and so much more. There is an emphasis on using Driver as opposed to Variable objects. Although, a deep dive into Driver is a whole other topic.

In regards to 2.1, the changes from 2.0 to 2.1 are minimal and had no impact on my work.

Enjoy the new stuff!

When and Why Did I Start Meditating?

Why does anyone do what they do? Curiosity is one driving force. Another force comes from beliefs. Beliefs form thoughts which inspire action.

Among other beliefs shared with me while growing up, I believed in actualizing my potential. Among other influences, this was impressed upon me by my parents and a special athletic group known as Sokol.

Formally known as the American Sokol Organization, I belonged to this gymnastics group for almost all of my life as a child. Sokol has the philosophy of a “A Sound Mind in a Sound Body.” Beyond the philosophy, it felt like a good idea. I never regretted attempting to actualize my potential.

While pursuing this continuous quest, I noticed that martial arts had a similar flavor of one being the best they can be. On top of that, the martial artists were doing something new and curious to me. They were meditating!

martial-arts-291046_1280

(Source: pixabay.com)

Based on my Sokol training, I knew that a healthy body wasn’t enough. Yet, how can one strengthen and actualize the mind? Being a kid and seeing meditating also happening in Star Wars, this meditation thing had to be explored! I went to the library and learned what I could.

To make a long story short, I was exposed to the basic techniques and many beliefs that came with my introduction to meditation. I meditated for many years. Over time, I shed myself of the beliefs which did not serve well. For awhile, I even stopped meditating since I wasn’t certain meditation was backed by science.

Just a few years ago, I came across some scientific proof that meditation yields a better brain. In short, increased focus and the ability to respond as opposed to blindly reacting to my emotions was something I gained. Now there was scientific proof from multiple sources too.

The question that remained for me was whether or not I was doing meditation well. I learned from some meditation iPhone apps that this is a common question. The simple answer is that one should just try their best and yet not focus “too hard.” What is especially important is to make meditation into a daily habit.

From what I learned from Nir Eyal and his excellent Hooked book, forming a habit is a well understood thing. For me, I came to understand that no matter what I will meditate daily even if it is for two minutes no matter how silly it felt. The daily repetition helped make it stick even in my most busy times.

So, the journey continues. As a thank you to others who have helped me on this path of self-actualization, I pay it forward. I share what I have learned with others.

Good luck with your own quest for excellence!

 

 

Swift structs, closures and Memory Leaks

Using structs and registering closures with a framework? Did you know closures are reference types?

If your closure is registered with a class from a framework and the closure is closing over self then you have a strong reference cycle memory issue. For example, let’s say we have a struct which has an RxSwift class Variable<String> member called someVariable.

When you give the subscribeNext the closure, it will store that closure into the framework. In other words, it has a reference to the closure. If you are referring to self in that closure, you have a strong reference cycle. The struct has a Variable which has a closure that has a reference back to the struct.

Can we just make the self reference a weak reference? No. Not if it’s a struct.

If it’s a class, we can do the following:

Note that we are using class and [weak self] now. We also took away the mutating from before the function.

That solves the memory issue! Thanks goes to some helpful humans which include Darren and Marc Khadpe in this Stackoverflow post.

Update: For an example such as this, Carlos García rightfully pointed out that using [unowned self] would be better. It’s faster and more. Carlos pointed out this article: How Swift Implements Unowned and Weak References and a related Twitter thread.

If you are going to use unowned, you will want to know when your app can crash when using it.  “Weak, Strong, Unowned, Oh My!” – A Guide to References in Swift is a good guide for when to use weak, unowned, and the default strong references.

Swift Protocols With Associated Types – PATs

What first led me into understanding Protocols With Associated Types (PATs)? Answer: RxSwift. It’s an awesome FRP framework for Swift.

What led me to the protocol compilation error “..can only be used as a generic constraint” which looks like this?

1PAT with compiler error

(Source: Alexis Gallagher – Protocols with Associated Types – 1:24)

Answer: Applying BDD (Behavior-Driven Development) to our Protocol Oriented MVVM RxSwift empowered code and using dependency injection.

We were going to use structs and protocols wherever we could. However, we had to back off some. Thanks to Alexis Gallagher, it’s clear now why we ran into the same problem that he presented in his video presentation, Protocols with Associated Types and how they got that way (maybe). Here’s a problem example he shows:

2PAT single variable declaration

(Same source: 2:47)

This great presentation was part of the 2015 Functional Swift Conference. The Protocols with Associated Types, and How They Got That Way slides are available. However, I highly recommend listening to the whole presentation. Since it’s 56 minutes long, this blog post links to certain key parts of it with associated snapshot images just to give you a taste of what is in there.

From this presentation, there are some crucial key takeaways:

  • Can’t use dynamic dispatch with PATs
  • typealias can do two very different things
  • There are workarounds if you need to do dynamic dispatch

Can’t Use Dynamic Dispatch With PATs

The compilation error “..can only be used as a generic constraint” described above shows how PATs are unique and different from plain old Protocols. The following dives into the ramifications of this situation:

3No Dynamic dispatch

(Same source: 6:54)

PATs are their own thing. As Alexis G. says, call them PATs and recognize how they are different.

typealias Can Do Two Very Different Things

4typealias two different uses

(Same source: 11:39)

As specified in the Swift Language Reference on Declarations, you can use typealias to:

  • Create a name for a type. See the “Type Alias Declaration” section.
  • Require something that conforms to a PAT, to specify a type. See the “Protocol Associated Type Declaration” section

Slide 18 of his presentation has a good example of showing typealias being used in a PAT.

There Are Workarounds If You need to do Dynamic Dispatch

11HowToLovePATs

(Same source: 39:08)

Workarounds are:

  • Enums
  • Type Erasure

The future looks bright if they add Existentials to the language. There is a Stackoverflow post about the generic concept an Existential Type.

Summary

Until they add Existential Types to the Swift language, we should fully understand PATs and how to use other parts of the Swift language to accomplish what we want.

As an aside: If you got this far, you really may want to watch the whole presentation on youtube. This blog post was made to just catch some of the interesting bits for later referral. Enjoy!

RxSwift Driver – What is it?

Curiosity is a powerful thing. When I saw this RxSwift Driver being discussed on RxSwift Slack and read the helpful RxSwift GitHub issue “Need better explanation / examples for Driver” submitted by Florent Pillet, it seemed helpful to capture what I saw.

As Carlos García shared on the GitHub issue:

One should think of the following:

as the same as:

Krunoslav Zaher aka kzaher on the RxSwift slack community said that it is a combination of: “main thread + shared subscriptions + no errors.” He goes on to say that shareReplay(1) is a shared subscriptions example. Carlos adds there are several examples in RxExample.

kzaher sums it all up nicely by sharing:

Yeah, it’s just a tiny builder/dsl for Observables. I think this should help me and others a lot with ensuring you can safely bind values to UI.

Using Driver is optional, but it helps the compiler catch things and will help emphasize things that might have been missed. As kzaher put it:

..and warn me when I’ve forgot to handle unexpected errors, or binding from background thread or doing something I should have when dealing with UI applications.

You may want to keep an eye on the RxSwift documentation as it grows and develops over time. Specifically, this Units document. Driver sounds exciting and I look forward to trying it in-depth in the near future!

Jan 2, 2016 Update: The Units document has been updated and much more has been added to it. Good stuff!

RxSwift Glossary and Concepts

Do you speak RxSwift? Do you know the concepts, words and operators? Here is a snapshot summary of many of them.

Some of the RxSwift Concepts from Getting Started

An Observable is a definition of: 

  • “..how the sequence is generated..”
  • “..what parameters are used for element generation..”

Disposing

“..release all of the resources that were allocated to compute upcoming elements..”

Observable aka Sequence

  • One after another, the Observable sends a Next (element), Error, or a Completed
  • What stops them from coming? An Error, Completed or dispose the subscriptions.

Observer

Subscribes to Observables

Subject

(Source: Rx.playground)

Terse mode: “acts both as an Observer and as an Observable”

Full mode: “A Subject is a sort of bridge or proxy that is available in some implementations of ReactiveX that acts both as an observer and as an Observable. Because it is an observer, it can subscribe to one or more Observables, and because it is an Observable, it can pass through the items it observes by reemitting them, and it can also emit new items.”

Operators

There is a list sorted by functionality at https://github.com/ReactiveX/RxSwift/blob/master/Documentation/API.md#rxswift-supported-operators

Operator Types:

(Sources: Rx.playground and github docs)

  • Combination operators – startWithcombineLatestmergeswitchLatestzip; “Operators that work with multiple source Observables to create a single Observable”
  • Conditional and Boolean Operators – takeUntiltakeWhile – “Operators that evaluate one or more Observables or items emitted by Observables.”
  • Connectable Observable Operators – multicastreplay, replayAll, publish – “like an ordinary Observable yet only when its connect() is called does it emit”
  • Error Handling Operators- catchErrorretry – “Operators that help to recover from error notifications from an Observable.”
  • Filtering Observables – distinctUntilChanged, filtertake; “Operators that selectively emit items from a source Observable.”
  • Mathematical and Aggregate Operators – concat, reduce – “Operators that operate on the entire sequence of items emitted by an Observable”
  • Observable Utility Operators – doOn, subscribesubscribeNextsubscribeCompletedsubscribeError; “toolbox of useful Operators for working with Observables”
  • Transforming Observables – map / selectflatMapscan; “Operators that transform items that are emitted by an Observable”
  • Units – “purpose of Driver unit is to ensure the underlying observable sequence has the following properties”: It “can’t fail”, “main thread”, and more.

Schedulers

Schedulers are an abstraction away from what does work (queues / threads).

RxSwiftCommunity

By the way, the RxSwiftCommunity bears checking in on from time to time. Action is listed there and it comes up often in the RxSwift Slack community and at least once in Stack Overflow. Just like the adoption of RxSwift, I sense the community will grow over time.

Update: If one looks at the code commits done for the RxSwiftCommunity website, one can easily see lots of activity going on.

RxSwift and Memory

Tom Burns asked a good question about TableView bindings outliving the view controller. As he said:

I’m asking because I noticed that some of my tableview bindings were outliving the view controller being popped back off the stack and it seemed like unnecessary work was being done…

kzaher of the RxSwift Slack community pointed out the following code as being the culprit:

Tom fixed the code to use an “[unowned self]” before the newObjects. Such as:

Although such memory situations aren’t limited to RxSwift, using RxSwift might encourage such situations to come up more often. It something to watch out for.

Regardless, this is something we all can run into from time to time. I feel fortunate enough to have caught the conversation in the RxSwift Slack community and am grateful to Tom for asking.