How to Debug and see NSData / Data in Xcode debugger

Xcode’s debugger is bad about letting you see what the contents of a Data / NSData object are. Here’s my workaround:

  1. Use po to print out the base64 version of the object, e.g.

2. Copy that to the clipboard, then use the command line in Terminal to turn that into readable content

pbpaste | base64 -D | xxd

If you know it is plain text you can omit the xxd part.

For example, here’s the output for a recent AlamoFire debugging session:

(lldb) po
some : "eyJzdWNjZXNzIjp0cnVlLCJwcm9maWxlIjp7InByb2ZpbGVzIjpbeyJmaWx0ZXJhYmxlIjpmYWxzZSwiZmlsdGVyX3ByaW9yaXR5IjpudWxsLCJmaWx0ZXJfdGV4dCI6bnVsbCwiZmlsdGVyX3BhcmFtZXRlcnMiOnt9LCJxdWVzdGlvbl9pY29uIjoiQmFzaWNzXzAwMiIsInF1ZXN0aW9uX2lkIjoyLCJ0YWdzIjpbIm9waW5pb25zIl0sImRlY2xpbmVkX3F1ZXN0aW9uIjpmYWxzZSwiY29tbWVudCI6IiIsImNyZWF0ZWRfYXQiOiIyMDIwLTEyLTA4VDE3OjM1OjEyLjk3NVoiLCJ1cGRhdGVkX2F0IjoiMjAyMC0xMi0wOFQxNzozNToxMi45NzVaIiwiY2hvaWNlcyI6W3sib3JkZXIiOjAsImFjdGl2ZSI6dHJ1ZSwiaWQiOjExMTk4LCJjaG9pY2VfaWQiOjI5LCJjdXN0b21fZW50cmllcyI6W10sImNyZWF0ZWRfYXQiOiIyMDIwLTEyLTEwVDE1OjQ5OjI5LjQwOFoifV19XX19"
? pbpaste | base64 -D | xxd
00000000: 7b22 7375 6363 6573 7322 3a74 7275 652c  {"success":true,
00000010: 2270 726f 6669 6c65 223a 7b22 7072 6f66  "profile":{"prof
00000020: 696c 6573 223a 5b7b 2266 696c 7465 7261  iles":[{"filtera
00000030: 626c 6522 3a66 616c 7365 2c22 6669 6c74  ble":false,"filt
00000040: 6572 5f70 7269 6f72 6974 7922 3a6e 756c  er_priority":nul
00000050: 6c2c 2266 696c 7465 725f 7465 7874 223a  l,"filter_text":
00000060: 6e75 6c6c 2c22 6669 6c74 6572 5f70 6172  null,"filter_par
00000070: 616d 6574 6572 7322 3a7b 7d2c 2271 7565  ameters":{},"que
00000080: 7374 696f 6e5f 6963 6f6e 223a 2242 6173  stion_icon":"Bas
00000090: 6963 735f 3030 3222 2c22 7175 6573 7469  ics_002","questi
000000a0: 6f6e 5f69 6422 3a32 2c22 7461 6773 223a  on_id":2,"tags":
000000b0: 5b22 6f70 696e 696f 6e73 225d 2c22 6465  ["opinions"],"de
000000c0: 636c 696e 6564 5f71 7565 7374 696f 6e22  clined_question"
000000d0: 3a66 616c 7365 2c22 636f 6d6d 656e 7422  :false,"comment"
000000e0: 3a22 222c 2263 7265 6174 6564 5f61 7422  :"","created_at"
000000f0: 3a22 3230 3230 2d31 322d 3038 5431 373a  :"2020-12-08T17:
00000100: 3335 3a31 322e 3937 355a 222c 2275 7064  35:12.975Z","upd
00000110: 6174 6564 5f61 7422 3a22 3230 3230 2d31  ated_at":"2020-1
00000120: 322d 3038 5431 373a 3335 3a31 322e 3937  2-08T17:35:12.97
00000130: 355a 222c 2263 686f 6963 6573 223a 5b7b  5Z","choices":[{
00000140: 226f 7264 6572 223a 302c 2261 6374 6976  "order":0,"activ
00000150: 6522 3a74 7275 652c 2269 6422 3a31 3131  e":true,"id":111
00000160: 3938 2c22 6368 6f69 6365 5f69 6422 3a32  98,"choice_id":2
00000170: 392c 2263 7573 746f 6d5f 656e 7472 6965  9,"custom_entrie
00000180: 7322 3a5b 5d2c 2263 7265 6174 6564 5f61  s":[],"created_a
00000190: 7422 3a22 3230 3230 2d31 322d 3130 5431  t":"2020-12-10T1
000001a0: 353a 3439 3a32 392e 3430 385a 227d 5d7d  5:49:29.408Z"}]}
000001b0: 5d7d 7d                                  ]}}

git tip: stage lines matching a regular expression

Have you ever wanted to make a big refactoring but realize now you’ve done too much for a single git commit?

What if there was a way to stage only the modifications that matched a regex (regular expression) somehow?

There is!

Use grepdiff. Install it from homebrew or macports. Use it to grep through the output of `git diff`.

First, preflight your regex to make sure it’s working:

git diff -U0 | grepdiff -E 'some[Pp]attern' --output-matching=hunk

Once it’s working well, pipe it to git to make it stage those lines:

git diff -U0 | grepdiff -E 'some[Pp]attern' --output-matching=hunk | git apply --cached --unidiff-zero

Then commit.

git commit -m "Rename the field somepattern to somePattern"<br>

Unknown field argument owner @ ‘onCreateXYZ’

if you run across an error like

{"errors":[{"message":"Validation error of type UnknownArgument: Unknown field argument owner @ 'onCreateXYZ'"}]}

While using AWS Amplify with DataStore, it’s probably due to your AppSync Schema being messed up. I’ve run into this when I had a model type two cognito @auth directives, e.g.

@auth(rules: [
{ allow: private, operations: [read] }
{ allow: private, provider: iam, operations: [create, read, update, delete] }
{allow:owner,ownerField: "owner" }

The code generator for AppSync gets confused in this case and creates incorrect Subscription definitions. They lack the `owner` parameter, as you can see if you sign into the AppSync dashboard for your environment, and tap on the Schema link.

This is the way it should look:

onCreateUser(owner: String!): User @aws_subscribe(mutations: ["createUser"])

But this is what gets created

onCreateUser: User @aws_subscribe(mutations: ["createUser"]

Just change your schema.graphql back to having only one cognito auth type and push. AppSync schema should be back to normal and the error on launch will go away!

take(1) can be dangerous

When putting together reactive networks using Reactive Extensions (e.g. RxJS in Javascript / Typescript), I often need logic that responds to a single event. `take(1)` is useful in this situation.

However, more than once, `take(1)` is a cursed operator, because it can easily cause an RxNetwork *to go dead*. This is because after a single event it completes.

It’d behoove one to remember this and make sure that’s really what you want. In this case, I was doing a `filter()` after a `take(1)` and it resulted in a reactive stream that send no events and just completed. I really needed to put the `filter` first.

AWS ElasticBeanstalk

“any attached Amazon RDS DB instance will be deleted”. This boldfaced warning is presented when you sometimes need to resort to last measures to get an EB instance back on its feet. Lest you panic, you can easily see if your EB instance is managing any RDS instances by looking at the Database section of the configuration. It may well be you don’t have any databases at all — but they present this error message regardless of whether you do or do not have any.

Untitled Poem by Frances Rahn

I have lost my two babies – a boy and a girl.

And all that is left is a bootie and a curl.

Oh, the years seem like sixty instead of sixteen

Since I ruled their kingdom as nursery queen.

Dearest prince, and sweet princess, I long to retain

The vision of you in your childhood domain

Where a baby’s low coo, and a toddler’s soft kiss

Were loaned by the Master of heavenly bliss.

Though the princess stayed only from Spring until Fall

Yet there isn’t a soul who will ever know all

That she took of my heart when, without any fright,

She closed her blue eyes and slipped out in the night.

But the prince is a man now – that is, he’s almost

A man, and a fine one, I’m eager to boast.

I have done what I’m able since he was a lad

To help him distinguish the good from the bad.

Though I’m proud of these seventeen years in review,

Some times, like tonight, how I wish he were two.

How I yearn like a beggar on horseback to ride

On back through the years with them on my side,

Little dimple-kneed princess and apple-cheeked prince,

Much sweeter that anything I have known since.



JSTimers is not a registered callable module

This can happen if you have two versions of react-native installed. I use yarn to install dependencies, and normally fix this by adding a resolutions section to my package.json:

  "dependencies": {
    "react": "16.9.0",
    "react-native": "0.61.5",
  "resolutions": {
    "@types/react": "16.9.0",
    "react": "16.9.0",
    "react-native": "0.61.5"
  "devDependencies": {
    "@types/react": "^16.9.0",

Make certain that the versions are consistent — otherwise multiple versions may end up installed by react and some of those versions will not be able to connect to the native dependencies, resulting in an error like JSTimers is not a registered callable module or Module RCTDeviceEventEmitter is not a registered callable module.

Working Goldfish

Our goldfish have returned indoors after another successful summer of eating mosquito larvae in the water lily pond (a 25 gallon plastic tub). I overwinter the water lily bulb in a 5-gallon bucket that’s loosely covered in the basement.  Then in March I fill the outdoor pond and put the lily in the bottom.  I wait until I see a few larvae swimming in the pond before I put the goldfish out. That first day they gorge themselves on all the larvae.  We’ve had these two 5-cent comet goldfish for 10 years now. They absolutely thrive in the bucket all summer, and nary a mosquito larvae survives while they’re on duty. I don’t feed them at all — enough bugs and leaves and algae and who knows what comes along that they are fat as can be all summer. Every November I chip them out from beneath the frozen water and bring them inside.  Let them temperature acclimate in their own pond water in a bucket inside for 24 hours.  Then carefully net them into the aquarium that’s been running empty all summer. They live inside all winter — we do feed them now of course — no random bugs dropping in while inside (I HOPE).

Their names are Harold and Henry.

React-Native Viewpager

Android has a view called a “viewpager”. It’s sort of like iOS PageViewController. There are several efforts to bring this to react-native as a cross-platform solution. rn-viewpager is now abandoned, even though it worked great. react-native-app-intro-slider is interesting, but seems special purpose for doing welcome screens — it doesn’t allow other interesting use cases because it seems to assume it’s always the full width of the device window. react-native-viewpager is another one but it’s Android only.

One that seems often overlooked is good old tabview. This can be customized so that the tabs themselves look like paging dots and it already has a nice “viewpager” style animation.

So next time you’re googling for react-native viewpager, maybe consider tabview as an easy solution. It’s well supported by the community and doesn’t have as big a risk of being orphaned like rn-viewpager was.