Debugging provisioning profiles on the command line

Raise your hand if you’ve ever struggled with getting your app’s bundle identifier, info.plist, and entitlements.plist to match up with your provisioning profile.

I tried to explain provisioning profiles using the ten-hundred most common words, but in slightly-less-common words, a development prov-pro associates: A team, a developer, an application identifier, privacy and security entitlements, and development devices.

While there’s no silver bullet, there is a way to dump the contents of a provisioning profile into a readable plist format. From the command-line, run:

security cms -D -i some.mobileprovision

Here, for instance, is the output of a provisioning profile for an app that uses SiriKit to trigger a workout:

napkin

As you can see, this is a convenient way to confirm the associations in the prov-pro, particularly entitlements, the app ID, and provisioned devices.

Mysterious crashes in your iOS 10 program? Check your info.plist

If you’re developing for iOS 10 and your app “silently” crashes (especially if it’s an older app), the culprit could well be the increased privacy requirements in iOS 10. Namepaces such as HomeKit now require specific privacy-related keys to be in your info.plist (for instance, NSHomeKitUsageDescription). If you don’t have them, the system automatically closes your application without an exception or Console.log message (if you run in the simulator, you may see a PRIVACY_VIOLATION notice in the stack trace).

Streaming a Web video to AppleTV with Xamarin

If you have the URL of a streaming video, it’s easy to display on an AppleTV, even though tvOS does not have a UIWebView (which would make it really easy). You have to use some AVFoundation code, such as:

var src = NSUrl.FromString("https://somevideo");
var asset = AVAsset.FromUrl(src);
var playerItem = new AVPlayerItem(asset);
var player = new AVPlayer (playerItem);
var playerLayer = AVPlayerLayer.FromPlayer (player);
//Might want to modify this so that it's the same size as the source video
var frame = new CGRect (0, 0, this.View.Frame.Width, this.View.Frame.Height);
playerLayer.Frame = frame;
this.View.Layer.AddSublayer (playerLayer);
player.Play ();

Note: This won’t work with normal YouTube page URLs since the YouTube stream URLs are not directly accessible.

The Half-Baked Neural Net APIs of iOS 10

iOS 10 contains 2 sets of APIs relating to Artificial Neural Nets and Deep Learning, aka The New New Thing. Unfortunately, both APIs are bizarrely incomplete: they allow you to specify the topology of the neural net, but have no facility for training.

I say this is “bizarre” for two reasons:

  • Topology and the results of training are inextricably linked; and
  • Topology is static

The training of a neural net is, ultimately, just setting the weighting factors for the elements in the network topology: for every connection in the network, you have some weighting factor. A network topology without weights is useless. A training process results in weights for that specific topology.

Topologies are static: neural nets do not modify their topologies at runtime. (Topologies are not generally modified even during training: instead, generally the experimenter uses their intuition to create a topology that they then train.) The topology of a neural net ought to be declarative and probably ought to be loaded from a configuration file, along with the weights that result from training.

When I first saw the iOS 10 APIs, I thought it was possible that Apple was going to reveal a high-level tool for defining and training ANNs: something like Quartz Composer, but for Neural Networks. Or, perhaps, some kind of iCloud-based service for doing the training. But instead, at the sessions at WWDC they said that the model was to develop and train your networks in something like Theanos and then use the APIs.

This is how it works:

  • Do all of your development using some set of tools not from Apple, but make sure that your results are restricted to the runtime capabilities of the Apple neural APIs.
  • When you’re done, you’ll have two things: a network graph and weights for each connection in that graph
  • In your code, use the Apple neural APIs to recreate the network graph.
  • As a resource (download or load from file) the weights.
  • Back in your code, stitch together the weights and the graph. One mistake and you’re toast. If you discover a new, more efficient, topology, you’ll have to change your binary.

This is my prediction: Anyone who uses these APIs is going to instantly write a higher-level API that combines the definition of the topology with the setting of the weights. I mean: Duh.

Now, to be fair, you could implement your own training algorithm on the device and modify the weights of a pre-existing neural network based on device-specific results. Which makes sense if you’re Apple and want to do as much of the Siri / Image recognition / Voice recognition heavy lifting on the device as possible but allow for a certain amount of runtime flexibility. That is, you do the vast majority of the training during development, download the very complex topology and weight resources, but allow the device to modify the weights by a few percent. But even in that case, either your topology stays static or you build it based on a declarative configuration file, which means that whichever route you choose, you’re still talking about a half-baked API.

Bizarre.

Review: 11-Day Diving on the Galapagos Master

Trip Review: Galapagos Master, 11-Night Liveaboard Diving

My wife and I recently returned from 11 days on The Galapagos Master, a 16-passenger liveaboard vessel whose itinerary includes Wolf and Darwin Islands.

The first thing to say about Galapagos diving is… Well, okay, the first thing to say about Galapagos diving is how incredible the fish life is. More on that in a minute…

The second thing to say about Galapagos diving is to talk about the temperature: temperature descriptions generally say something like “60-76F” and you might think “Well, I’ll plan for the middle of that estimate: 68F.” But that’s not right: the diving here is 60F or 76F, depending on where you dive. And even though almost exactly half the dives are in water that was in the mid-70s, the “feel” of the water temperature was determined by those in the 60F area. So 7mm hooded wetsuits and I envied the one person on our boat who dove in a drysuit. (My wife says her 5mm with a 3mm hooded steamer and a LavaCore was also okay, and she had more flexibility on the warmer dives.)

The other thing, for me, is gloves. I never wear gloves since in general I have no need to touch the reef. But in the Galapagos the large majority of dives involve tucking in to rocks and holding on in strong currents. Additionally, at Darwin, Wolf, and Cabo Douglas (Fernandina) there was surge.

And the rocks are covered in barnacles. I didn’t wear gloves for the first several dives and my hands got sliced up.

Dives are limited to 50 minutes. We were all diving nitrox and spending the majority of our dives at 60-80’, so I thought that duration was good: long enough to linger when the sights were good, short enough so that air consumption wasn’t a limiting factor, and brief enough that no-deco was very manageable (I had a few 4th dives where I was deco-limited.) In the cold water at Cape Douglas (marine iguanas) and Punta Vicente Roca (molas and penguins) the dives were shorter — 40 minutes. (The water was cold, but with the marine iguanas my max depth was 19’! I would have happily spent more time with them.)

Each buddy-team was given a DiveRite audible alarm powered by their low-pressure BCD inflator and a Nautilus Lifeline GPS/VHS radio. We never had any cause to use either, but the Nautilus, in particular, struck me as a showing a good concern for safety.

Itinerary and Diving

Our 11-day itinerary was: board the boat in Puerto Baquerizo Moreno on San Cristobal. Same day we had a 20-minute check-out dive in the harbor: cold, poor vis, just a chance to get your weight correct. (Some sea lions came in and played with us, which was fun.)

2nd day was a dive apiece at Mosquera and North Seymour Island. I thought these would be more “check out” style, but actually the dive at Mosquera was excellent! First hammerhead of the trip, a big school of mobula, schools of barracuda, steel pompano, big blue-spotted trevally, “some kind of bonito.” Our 2nd dive, at North Seymour, was apparently more-commonly a highlight, but we got somewhat skunked.

We did a brief land excursion on North Seymour and, for me, it was one of the highlights of the trip — our only chance to see nesting blue-footed boobies and frigate birds. We saw several males displaying, a few pairs “dancing,” and even one sitting on an egg. (I’m kicking myself at missing a post-dive-trip day-trip to Isla Lobos from San Cristobal to see more breeding birds.)

Then we steamed for Darwin Island. We apparently got a late start for this, leaving North Seymour at 4:30PM when we were “expected” to get out of there at 1:30PM. (But that’s a little confusing to me, as we may have dawdled an extra 30 minutes or whatever on the land expedition, but the overall schedule was set by the boat.)

The upshot was that we didn’t arrive at Darwin until 8:30AM and dove immediately. The next 4 days (2 at Darwin, 2 at Wolf, 4 dives per day) were amazing. Warm, with occasional hints of a thermocline, moderate-strong currents (I think once we had a spot with something like 2 knots), insane density of fish. Jacks, hammerheads, Galapagos sharks, yellowfin tuna, smaller tuna… just amazing.

Visibility was not “murky” but it was definitely “hazy.” Maybe 25-35’-ish total, but things at the limits of visibility were definitely more silhouette-y than defined. So even though there was tons of wildlife, you would really only very-clearly see maybe 3-4 close passes per dive.

Our panga (“Jaguar Sharks!”) was quite experienced (professional divemasters, marine biologist, etc.: with just over a thousand dives, I was by far the least experienced). I think on a difficulty scale of 1-10 for recreational diving, this was 7-8 stuff: cold, currents and surge, limited viz. This would not be a place for divers uncomfortable with their gear.

Additionally, particularly at the south side of Darwin’s Arch, if you drifted away from the group and were not in the panga right around that 50-minute mark, you could get close to some extremely dangerous wave breaks. The dive guides knew the topography and drifts very well and if you paid attention to the rules and stuck with them, it was all fine. But again, it was the type of place where a mistake that separated you from the group could get very serious, very quickly.

I could go on for thousands of words detailing the diving, but suffice it to say that it was great. There were endless schools of predators such as jacks and bonito as well as reef fish such as creole fish. The sharks varied depending on the specific dive location and time of day, but typically you’d settle in at 3 or 4 stops along the reefs and usually when you settled in, some amount of hammerheads and Galapagos would come by. Sometimes, when the current was strong, you’d be in a perfect situation where the hammerheads were slowly making their way up-current and it was just an unending conveyor belt.

Another fun thing to do at Darwin was to drift past the boat on its mooring: there must have been 20 silky sharks swimming along in its eddy and if you could hold on to a panga line or get into the eddy at the stern of the ship, you would just be surrounded by silkies. The islands and birdlife of Darwin and Wolf were fascinating to observe with binoculars from the stern of the ship.

After Darwin & Wolf, the diving was one location per day, usually with a single dive site dived only 3 times per day. In our case, we often dove, 7:45AM, 9:45AM, 11:45AM. Generally diving did seem to deteriorate as the morning progressed, so the only way I’d change that schedule would be a dive before breakfast, but that was never presented as an option to us. I think there was one more day when we had an after-lunch dive.

Fernandina had a beautiful deep-dive to see horn sharks and red-lipped batfish (coldest dive, with 58F on my computer and 95’ of neoprene compression). After that, we did 2 dives in 5 meters to see marine iguanas feeding. Absolutely amazing. I do want to say that when we first got in, I experienced the most powerful surge of the trip: the surge was so strong that it caused my octopus to freeflow and then, even with a good grip, I got peeled off a rock and pushed a solid 10 yards. Again, this is a situation where a less experienced person could make a serious mistake and try to re-grip rather than accept spending the next few waves being washed back and forth.

Another highlight of the trip then occurred: while crossing from Fernandina to Isabella I spotted a pod of orcas in the distance. They approached the boat and checked us out for ten minutes or more, swimming right alongside the boat, tilting on their sides to look up at us, etc.

As with the iguanas at Fernandina, the next two days were destination dives as well: one day to see molas (ocean sunfish) and penguins (snorkeled with one) and the next to see pelagic manta rays. These were fine and again the walls were beautiful, with abundant black coral and bushy brown gorgonians teeming with long-nose hawkfish.

Then a long cruise to Cousin’s Rock near Santiago and the final 2 dives of the trip. I feel silly downplaying any diving that involves a cave filled with white-tipped reef sharks and sea lions but compared to the other diving on the trip, this was anti-climactic.

The final half-day of the trip involved a bus ride to a farm in the Santa Cruz highlands to see giant tortoises. This was quite good: they were free-ranging and it seemed more natural than seeing them in pens. As a reminder of the threat of introduced species, I was bitten by a fire ant as I watched a giant tortoise.

Then we went down to Puerto Ayora and spent several hours, having a couple drinks and lazily shopping for souvenirs. The bus picked us up at 6:30PM and got us back to the boat near 8PM, where we had a final cocktail reception where the “tipping” occurred (more on that below) and then dinner. (Again, this was a case where the schedule was set by the boat, so the fact that we were all starving by the time we were fed near 9PM seems like something they could adjust.)

The next day we were back in Puerto Baquerizo Moreno and taken off the boat at 830AM.

The [official itinerary] describes the cadence as an early dive, breakfast, morning dive, lunch, and two afternoon dives. That’s not at all how ours worked: first, we never had an opportunity to dive before breakfast and on 3-day dives (most days not on Darwin and Wolf) we often did all 3 dives before lunch with only 45-minute breaks. That was fine, since diving was generally better in the morning and getting in and out of a cold wetsuit is a pain.

Accommodations

The Galapagos Master is the former Deep Blue (so you might search for other reviews under that name). There are 4 below- and 4 above-deck cabins. We had an above-deck cabin but I do not think they were worth extra: the windows did not open and being that far above the center-of-gravity of the ship may have made the motion a little more obvious. Other than the standard shipboard reaction of “Oh my god, where are we going to put all our stuff?” the two things that stand out are the beds, which were very uncomfortable (pads over wood, with two single beds pushed together so that the rails created a “chastity bump”), and the electric toilet, which was absolutely incapable of clearing solids (if you know what I mean) with anything less than 4-5 flushes. Toilet paper goes into a container at the side.

There is a salon where the in-door socializing happens, with a big-screen TV with HDMI inputs, so it was easy to do slideshows or watch movies from computers. The mess had one large table and a few smaller ones. It was well-configured for socializing. The sundeck was the major socializing place, and once clearly sported a bar and chairs, but only one chair was attached. Instead, you just lounged along the rails.

I’m not a “foodie” and I thought the food was fine, but I think there was a little eye-rolling from some more refined people. There was always a salad and some amount of vegetables, and then usually a fish and a meat dish with some starch like potatoes or rice or plantains. Often meals started with a soup and there was always a dessert. There were two vegetarians on our trip and the galley seemed to be able to accommodate them well enough. Soft drinks were complimentary, beers were $3 apiece and cocktails and spirits were $6 apiece. Bottles of wine were $25.

The dive deck was quite good, with individual stations along the rails, a wetsuit cleaning-tank and rack in the middle, 2 hot-water hoses with shower nozzles, and a large cameras-only tank. Under the tanks were cubby-holes with milk crates in which you kept your miscellaneous dive gear. Up a few steps from the dive deck was a passage with a long camera bench with 2 air blowers (well, 3, but one wasn’t working). On the other side there would be post-dive snacks and hot chocolate or ice tea. A nice thing were post-dive towels, neatly labeled with your station number, so you would be assured of getting one.

On the first day our nitrox was a little low, at 29+, but mostly we dove around 32% O2. Again, I thought the nitrox vs. time vs. depth balance was just right: you ended the 4-dive days close to deco-limited but I never got close to depth-limited.

“Tipping”

This is a pet peeve of mine. I’m from the US and I tip well because I know that, when “tipping” is a big part of how workers make their money, workers get absolutely screwed. Our trip had people from the US, England, and Germany, all of which have vastly different attitudes and expectations about tipping. And although “it’s absolutely up to you” there is a “recommended 10% tip” on your $600-a-day-per-person dive trip that is “an important part of how the crew make money.” This is total BS! If a fair wage for the crew amounts to $60 per day per guest, charge $660 per day and make tipping truly optional.

As one guest from England, who was not prepared to tip in cash (which is the only way), said “Half the trip fee goes to the cost of fuel for the ship. Why am I paying 10% of the fuel cost for ‘service’?”

Also, “tipping” this way creates perverse incentives. After safety, the most important role of the diveguides is to enforce the conservation rules, but that’s made more difficult when you rely on “tips” as a major part of your income for the trip. Which brings us to…

“That Guy”

One of the things we got ready to board the boat is that “there’s always one guy.” In our case, he was a German who fancied himself a “photo-journalist.” What that meant was that in his mind, because he made a few thousand Euros per year from stock photography fees, he was justified in breaking the rules: he didn’t stay in a line so that all divers were at an equal distance from the skittish hammerheads, he dive-bombed other photographers, he pushed my wife out of the way when she had the temerity to videotape a marine iguana with “just” a GoPro, and, worst of all, he would swim up to skittish animals such as hammerheads or mola and blast them with his strobes. He was clearly out of line time-and-time again, and the dive guides never confronted him.

This became a topic of every post-dive talk and we talked to our dive guide about it. He spoke at dinner about the importance of obeying the no-harassment rules and the dire consequences of breaking them. Then again, at breakfast the next day, he reiterated the importance of not chasing the animals.

And then, an hour later “That Guy” bombed a Mola and chased it away. Back on the panga, the other divers were saying stuff and when it became clear that the dive guide wasn’t going to say anything, I gave the guy both barrels. The upshot? Well, he didn’t dive with us anymore, but essentially he got a private dive guide and (according to reports) had a great time swimming up to and blasting pelagic mantas.

Such behavior will continue as long as the rest of us divers, whether photographers or not, tolerate it. We all want to see the animals as well as possible, we all paid a lot of money, we all would love a photo. But sometimes nature doesn’t accommodate our wishes. What we do in those circumstances is the test of our character and, if you label yourself a “photographer” (much less a “photo-journalist”), a test of your ethics.

Don’t be “that guy.”

WWDC Remote Viewing Protips

I attended the 2015 WWDC and made these notes afterwards. Aside from the specifics re. the Apple Watch and AppleTV, they may be of value to those who are considering streaming sessions next week:

WWDC: Post-show Streaming is the Key to Value

From an editorial perspective, one thing that is clear about WWDC is that the main audience for the sessions is not the developers in attendance, but the much more diverse, more diffuse, and more transient on-line audience that will view the videos over the next months and even years.

WWDC Session Videos are great as overviews, poor as references

What I’ve come to realize is that WWDC sessions are great as overviews, but poor for depth. They are very much worth watching when you’re new to a framework, they’re somewhat worth watching if you haven’t programmed in the framework lately (you might see some class you hadn’t appreciated), but they are not the place to discover a way out of some corner-case or programming limitation.

Microsoft explicitly labels the depth of their conference talks as being 100-, 200-, or 300-level, and 300-level content at WWDC was vanishingly rare. (As I write this, I can only speak to the talks I physically attended, but several talks definitely promised more depth than they delivered.)

I wonder if this is an artifact of The Dog That Didn’t Bark aka Apple TV. It must have been pulled very late. Both Xcode and Apple’s Developer Site, which had to be updated to support the new OS betas, are littered with Apple TV references. Perhaps it was the case that some of these talks were put together quickly. (Although you wouldn’t guess it from the universally well-practiced speakers.)

The real keynote was the Platform State of the Union

Monday’s keynote was covered by news vans and live blogs and all that crap. There was, perhaps, 5 minutes of developer content in this 2.5-hour stemwinder. From the audience, anyway, the music stuff was awkward to the point of embarrassment.

Skip it and watch [Platform State of the Union] instead. This was the true developer’s keynote and contains an excellent overview of El Capitan, iOS 9, and watchOS. (By the way, the witty kids pronounce “watchOS” so that it rhymes with “nachos.”)

The Shocking Secret You Can Use to Determine Which Videos to Stream

Is that a proper 21st century headline?

Anyway, here’s the key: many sessions followed a standard naming practice:

— “Introduction to…” talks are 100-level (if that) “tables of content.” They hardly have any code on screen, but contain references to other videos that provide the 200- or 300-level content. If you’ve ever programmed in the namespace before, you can skip these talks.

— “What’s New In…” talks are 100-level “Release Notes.” There may be some code, but what you’re really looking for here are the new classes and general new capabilities. This is the video with which you should start if you have programmed in the framework before, even if you’re pretty comfortable. Again, all of these talks are good at referencing other, more substantive, talks. This is my main recommended tactic for finding deep content on frameworks with which you are familiar: it’s much more effective than guessing from session titles and descriptions.

— Beware talks that have the words “tips”, “tricks,” or “practices.” These were the talks that disappointed me. Such words traditionally mean 300-level content. If you’re an attendee and you’re budgeting precious in-conference time to “tricks” and “practices,” that’s a strong indicator that you’re familiar with the framework and are encountering its limitations and corner cases. But at WWDC, these sessions appear to be more focused on the newcomer or relatively inexperienced framework user.

Tracking Apple Pencil angles and pressure with Xamarin

Rumor has it that Apple will support the Apple Pencil in the forthcoming iPad. If so, more developers will want to use the new features of UITouch — force, angle, and elevation — supported by the incredibly-precise stylus.

Basically, it’s trivial:

— Force is UITouch.Force;
— Angle is UITouch.GetAzimuthAngle(UIView); and
— Angle above horizontal is UITouch.AltitudeAngle

(The UIView objects are there, I think, to make it easier to create a custom angular transform that is more natural to the task at hand — i.e., an artist could “rotate” the page slightly to accommodate the angle with which they like to work. I think.)

Anyhow, here’s some code:


namespace UITouch0

open System
open UIKit
open Foundation
open System.Drawing
open CoreGraphics

type ContentView(color : UIColor) as this = 
   inherit UIView()
   do this.BackgroundColor <- color

   let MaxRadius = 200.0
   let MaxStrokeWidth = nfloat 10.0

   //Mutable!
   member val Circle : (CGPoint * nfloat * nfloat * nfloat ) option = None with get, set

   member this.DrawTouch (touch : UITouch) = 
      let radius = (1.0 - (float touch.AltitudeAngle) / (Math.PI / 2.0)) * MaxRadius |> nfloat
      this.Circle <- Some (touch.LocationInView(this), radius, touch.GetAzimuthAngle(this), touch.Force)
      this.SetNeedsDisplay()


   override this.Draw rect = 

      match this.Circle with
      | Some (location, radius, angle, force) ->
         let rectUL = new CGPoint(location.X - radius, location.Y - radius)
         let rectSize = new CGSize(radius * (nfloat 2.0), radius * (nfloat 2.0))
         use g = UIGraphics.GetCurrentContext()
         let strokeWidth = force * MaxStrokeWidth
         g.SetLineWidth(strokeWidth)
         let hue = angle / nfloat (Math.PI * 2.0)
         let color = UIColor.FromHSB(hue, nfloat 1.0, nfloat 1.0) 
         g.SetStrokeColor(color.CGColor)
         g.AddEllipseInRect <| new CGRect(rectUL, rectSize)
         g.MoveTo (location.X, location.Y)
         let endX = location.X + nfloat (cos(float angle)) * radius
         let endY = location.Y + nfloat (sin(float angle)) * radius
         g.AddLineToPoint (endX, endY)
         g.StrokePath()
      | None -> ignore() 

type SimpleController() = 
   inherit UIViewController()
   override this.ViewDidLoad() = 
      this.View <- new ContentView(UIColor.Blue)

   override this.TouchesBegan(touches, evt) =
     let cv = this.View :?> ContentView
       
     touches |> Seq.map (fun o -> o :?> UITouch) |> Seq.iter cv.DrawTouch

   override this.TouchesMoved(touches, evt) = 
      let cv = this.View :?> ContentView
      touches |> Seq.map (fun o -> o :?> UITouch) |> Seq.iter cv.DrawTouch
   


[<Register("AppDelegate")>]
type AppDelegate() = 
   inherit UIApplicationDelegate()
   let window = new UIWindow(UIScreen.MainScreen.Bounds)

   override this.FinishedLaunching(app, options) = 
      let viewController = new SimpleController()
      viewController.Title <- "F# Rocks"
      let navController = new UINavigationController(viewController)
      window.RootViewController <- navController
      window.MakeKeyAndVisible()
      true

   
module Main = 
   [<EntryPoint>]
   let main args = 
      UIApplication.Main(args, null, "AppDelegate")
      0

And it looks like this:

Airport Time Capsule considered harmful

The premise of the Apple ecosystem is “It just works.” It is a world of hardware and software in which you pay a premium for not having to worry about fiddling with configurations and command-line options and incompatibility.

The Airport Time Capsule is a wireless router that also contains a hard drive for backups and media sharing. Bizarrely, though, the hard drive it contains is not accessible to OS X’s Drive Utility program, so a run-of-the-mill filesystem error can cause the disk to be inaccessible. It’s the antithesis of “It Just Works.” It’s “It Just Will Not Work.”

Don’t buy an Airport Time Capsule.

Hair-Tearing-Out-Thing Explainer (Provisioning Profiles):

There is a company called Round Red Food. They make brain-phones and brain-watches and brain-televisions. These brain-things run brain-books written by Round Red Food. But Round Red Food also allows other people to write brain-books.

Round Red Food wants to control what brain-books run on their brain-things. To do this, they give each brain-book it’s own long name. This is called the Brain-Thing-Name.

Brain-books are written by many people, who come and go all the time, but the brain-book is owned by a thing Round Red Food calls the Team. Round Red Food knows all the teams and gives each one it’s own funny name. This is called the Team-Name.

Every brain-book needs a name, too. This name is added to the Team-Name to make the Book-Name.

Round Red Food wants to control what brain-books do so that bad Teams cannot make their brain-books do bad things like listen to you without your okay. Each brain-book has to do things. Every brain-book needs to run, but some brain-books also need to know where they are. Some need to take pictures. All sorts of stuff, but you should always be able to say okay or “No, I don’t want to allow you to do that.” The things that a brain-book needs to do are called its Needs-Doing-Things.

The people who write brain-books for a Team are coming and going all the time. So Round Red Food wants to know who is working for what Teams. Instead of saying “Keep your Team-Name and your Book-Names all to yourself and change them every time someone comes or goes,” Round Red Food lets the people who work for a team hold onto a special thing. This special thing is a Something-Everyone-Knows/Something-Only-You-Know numbers thing. As long as both the Team and the person working for the team agree, this thing makes a promise that the person works for the team. This Promise-Paper can be broken by either the Team (if they make the person go) or the person (if they don’t want to work with the Team anymore).

So, remember:

* the brain-thing has a Brain-Thing-Name;
* the brain-book has a Book-Name and a Needs-Doing-Things thing;
* the person working for the Team has a Promise-Paper

The people writing the brain-book send all this stuff to Round Red Food’s Brain-Book Writer’s Place. Round Red Food sends them back something that says “OK, this person, who works for Team, can put the brain-book named Book-Name on Brain-Thing-Name, and the person reading the brain-book will be asked whether they want to allow the brain-book to do its Needs-Doing-Things things.”

This is called the Tearing-Hair-Out-Thing.


Brain-Thing-Name -> UDID
Book-Name -> AppID
Needs-Doing-Things -> Entitlements
Promise-Paper -> Certificate
Tearing-Hair-Out-Thing -> Provisioning Profile

Animating the stroke color of a CAShapeLayer with Xamarin

I wanted to indicate the most recent move in an AI-on-AI game of TicTacToe, so I wanted to have the most recent move be highlighted. The Xs and Os are CAShapeLayer objects.

Here’s the code to do it, featuring a very ugly hack to cast an IntPtr to an NSObject Including the use of SetTo and SetFrom to use a type that is not an NSObject in CABasicAnimation (thanks Sebastien!):

var layer = mark == 'X' ? ShapeLayer.XLayer (endFrame) : ShapeLayer.OLayer (endFrame);
layer.Position = origin;
this.Layer.AddSublayer (layer);

var animation = CABasicAnimation.FromKeyPath ("strokeColor");
animation.SetFrom(UIColor.Green.CGColor);
animation.SetTo(layer.StrokeColor);
animation.Duration = 0.5;

layer.AddAnimation (animation, "animateStrokeColor");