Swift TIL 2

Posted on 2020-06-23 14:21 +0100 in TIL • Tagged with Swift, Apple • 1 min read

Following on with writing little notes to myself so I remember some key things as I learn about Swift...

I sort of feel like this will make reading code a little harder, so it's one I want to keep in mind. When calling an instance method, if it's not ambiguous, you can omit self. from the call. For example:

class Foo {
    private func inner() -> String { "Foo" }
    func outer() -> String { inner() + self.inner() }
}

print( Foo().outer() )

This makes me feel a little uneasy, and I strongly suspect I'll always use self. when writing such code: I'm a big fan of the idea that we write code for people, not for compilers.


Swift TIL 1

Posted on 2020-06-22 13:18 +0100 in TIL • Tagged with Swift, Apple • 1 min read

As I mentioned yesterday, I'm going to make a small series of posts where I write down things that I've stumbled on while getting to know Swift that are, for me personally, worthy of note, different, unusual, cool, or just simply "WTF!?!".

Because learning new stuff is fun.

My first one is that you can use keywords as identifiers if you "escape" them with backticks. Kind of like this:

let `let` = "let"

print( `let` )

I'm struggling to imagine a situation where I'd ever want to do this. I'm still unsure if my reaction is "that's cool" or "WTF?!?".


A second attempt to learn Swift

Posted on 2020-06-21 14:48 +0100 in Coding • Tagged with Swift, Apple, coding • 4 min read

It's five years ago this month that I bought myself my first macOS (then OS X) device. After many years of having a Windows machine as my daily driver, which was also my work machine (I worked from home), I decided it was high time that I returned to having a Unix-a-like system on my desk too. For a decade or so, starting in the later-90s, I'd had a GNU/Linux desktop. I still had a Windows desktop (until a couple of years ago most of my work was on DOS and Windows), but thanks to the wonders of a KVM, and later an X server that ran on Windows, my personal hacking was done on a GNU/Linux desktop.

But as things moved around, priorities changed, as life moved on, the GNU/Linux boxes got retired and never quite replaced. Eventually, in 2015, I found myself with the means and desire to recover that sort of setup. Long story short, after a lot of reading up and weighing up options I decided that the best option for a desktop Unix was... an iMac!

I loved it. Sure, there were lots of little things on the surface that were different or annoying or just plain not as cool as the Mac fans would tell you, but under the hood I found what I needed: a Unix CLI with all the things I knew well. And, of course, it ran GNU Emacs just fine; that was the really important thing for me.

Pretty much right away I decided that it might be fun to learn the tools necessary to develop native Mac apps, and perhaps even iOS apps. I downloaded XCode, bought a book, and started working through it. Having got that book, I decided it might be interesting to own an iOS device too. So, sort of needing an MP3 player, and having no wish to get an iPhone, I got myself an iPod Touch. So I was all set to devour the Swift book, write some stuff for OS X, create an iOS app or two, and... life happened. Stuff cropped up that distracted me from taking that further and I never really returned to working through the book.

Fast forward to now and that initial iMac and iPod purchase spiralled a wee bit. Next after the iPod was an iPad Mini, when my Nexus 7 was starting to show its age and it was obvious that Google wasn't going to produce any more good Android tablets. Then, when I needed a very portable Unix-a-like machine for trips between where I was living and Edinburgh, I got myself a MacBook Air. Since then the iPod Touch has been replaced once, as has the iPad Mini. I now also own an iPad and a MacBook Pro. Unless Apple screw up and turn Macs into something unusable for developers (there are rumours), I imagine I'll be using Apple devices for some time to come now.

And then, last month, having finally got frustrated with where Google were going with Android and the Pixel series, I jumped ship to the iPhone 11.

As of right now I'm in a situation where I'm all about the Apple ecosystem regarding hardware and operating systems (including for my work machine), all of which is there to support my heavy use of the Google ecosystem (actually, the one bit of Google hardware I still lean on heavily is the Google Home -- I have 3 around my home).

So... given all of that, I thought it was time to look at returning to learning Swift, with a view to writing some native macOS and i(Pad)OS stuff. I soon realised that the book I'd bought back in 2015 was rather out of date. It covers Swift 1.2 -- we're now up to 5.2! Given this, and given I've forgotten pretty much everything I'd read at the time, I decided I should start again from scratch.

This weekend I've started reading my way though iOS Programming Fundamentals with Swift. While this obviously has an emphasis on iOS, I'm already finding that the first part of the book is a really great introduction to the Swift language in general. The pace seems just right, and the way topics are grouped makes it easy enough for me to skip over what's obvious (I don't need to know what objected-oriented programming is, and what the difference between a class and an object is, etc) and read up on the detail of this particular language when it comes to general concepts I know (knowing the differences between a class, struct and enum in the language is important, for example).

I've yet to write a line of code, but I'm fine with that. The book is spending a lot of time introducing the language before encouraging you to fire up XCode, and I'm okay with that. I'm never a fan of being asked to write out code that I can't properly follow -- that just makes stuff look like magic when it's far more educational to know what's going on. What I am finding is I'm making lots of notes that are either "oh, yeah, this is cool, I like this idea!" or "WTF are you kidding me?!?". Which is really nice -- it's always great to learn a new language that's a bit different from what you normally use.

My plan then, over the next few weeks, it to keep at this and hopefully document my journey. I think I'd like to write a short series of TIL-type posts; nothing too long, just some new thing I read or discovered and my reaction to it. So, if you happen to follow this blog, I apologise in advance for any Swift-spam.

You have been warned. ;-)


A bit of a backlog at the Apple store

Posted on 2016-11-03 13:45 +0000 in Tech • Tagged with Apple, iMac, OS X • 2 min read

Over the past couple or so weeks my Macbook air has started to develop a minor, but irritating, hardware problem. Simply put, the left shift key fails now and again. I can press it and it does nothing. It's irritating because it messes with the flow of typing (especially when writing code) and the key also feels like it's sticking or clicking in a way that's different from all the other keys.

Macbook Keyboard

Given that I pass through Edinburgh on a pretty regular basis I thought I'd drop in and have a quick chat with someone about it. While I didn't expect a fix there and then (although finding out it was a trivial issue would have been nice) I was hoping someone could take a quick look and let me know what might be going on.

So, this morning, on the way to Waverley Station, I dropped in to the Apple store on Princes Street.

I walked in and looked for a member of staff, all seemed to be busy to start with but one soon noticed that I looked a little lost and asked me if they could help. I explained the issue and she said I needed to pop upstairs to chat with the staff up there.

So far so good.

So, I headed up to the first floor and caught the attention of another member of staff. Having explained the exact same thing to them I was told I needed to speak with yet another staff member. The chap I needed to speak to had a queue (yes, a physical queue of people) waiting to speak to him.

I joined the queue.

About five minutes later I got to speak with him. I, again, explained the problem and was told that looking at it would be no problem and they could do so at around 4pm. This was at about 10am. Having gone through 3 people and spent 10 minutes doing so I found out that there was a six hour queue to have someone actually take a quick look at the issue.

By that time I wouldn't even be in the same country, let alone the same city. So I had to say thanks but no thanks.

So now it looks like I have to make an appointment for some point in the future and make a special trip into Edinburgh just so someone can check out a sticky key on my Macbook.

Remind me again how the nice thing with Apple gear is that it "just works"...


I now own a Macbook

Posted on 2016-04-28 20:07 +0100 in Tech • Tagged with Mac, Apple, iMac, Unix • 3 min read

I've had my iMac for about 10 months now and I can safely say that it's a purchase I don't regret. While I'm still not convinced by the hype and nonsense that's normally associated with Apple products -- I've had plenty of moments where the damn thing really hasn't "just worked" -- I really do like the iMac as a Unix workstation.

Recently I've had the need to consider buying a small laptop that I can use on train journeys. While I have a very capable Windows laptop it's a little too large to pull out and use on the tray you get on the back of a train seat. I also have a much-loved Chromebook but it would generally fail me on the train unless I always pay for the WiFi. So the ideal machine for me would be fairly small (no more than 12" or so), be capable of doing things locally, and would also need a pretty good battery life (while the trains I travel on do provide sockets they seem to provide no power as often as they do).

I did start to think about going with some sort of Macbook but, every time I looked at them, I ended up deciding they were too expensive.

Until yesterday. Yesterday I found that the local computer store had the 13" Macbook Air on sale -- £150 off the usual price plus another £50 off if I got there and bought it before 5pm.

So I had to go and look.

Having looked I came away with one.

My new Macbook, on the train

So far I'm very pleased with it. While the one I have is the lower spec version (just 128GB of SSD and 4GB of memory) it seems to work well for my needs.

As for what my needs are? I want to be able to work on web projects locally, hack on JavaScript and HTML, that sort of thing. As well as that I want to be able to run Git and, when I do have a net connection, sync to GitHub and browse the web, do email, faff around on reddit, etc.

For this it's perfect. I'm finding it more than fast enough for what I want (I'd even go so far as to say that it's faster than the iMac). The keyboard is just the right size, the trackpad is perfect (and works just like the Magic Trackpad I use on my iMac), the screen is very readable. So far I'm struggling to find any real fault with it.

Okay, sure, there are some obvious downsides, the main one being that, for what I paid for this, I could probably have got a lower-end gaming Windows laptop with plenty of drive space, memory and a good graphics card. But that's not what I was after. A machine that big and that powerful would sit in the laptop bag and not get used. I wanted a machine that was easy to drag out, open up and use.

And that's what's happening with the Air. In fact, it's being used on the train right now; that's where I'm waffling on about this, to kill time, somewhere north of Newcastle, with the sea to my right and the snow coming down.


How to kill OS X's HelpViewer

Posted on 2015-11-02 15:38 +0000 in Tech • Tagged with Apple, iMac, OS X • 1 min read

A little earlier today I decided it was time that I read up a little more about the abilities of OS X's Spotlight facility. I use it a little -- it's a handy tool to get at some often-used applications that I don't really need laying around in the dock -- but I was starting to wonder if I could get more out of it.

The obvious first place to look was in the HelpViewer; all the information I'm ever going to need will be on the local machine, right?

So I open the HelpViewer, from the Spotlight bar, and type in that I want information about Spotlight. The page comes up blank. The page was pretty small so, while I pondered why it might be blank, I resized it and it disappeared! I tried to open it again and.... nothing. Nothing I did would make the HelpViewer show again.

I then tried following the advice on this page but none of that appeared to help. I then looked for the HelpViewer in the Activity Monitor and killed it with that.

Running it again after that got me back to where I started. I tried the while process again and, sure enough, trying to resize the window made it disappear. I can make it happen every single time:

So it looks like another fine example of the Apple "it just works" thing. For "doesn't always just work" values of "just works".


Apple Accounts

Posted on 2015-10-21 15:36 +0100 in Tech • Tagged with Apple, OS X, iMac, SMB • 2 min read

As much as I like my iMac, and as much as I am generally impressed with OS X the more I use it, I'm constantly frustrated by the little issues I run into that make life so much more interesting and which fly in the face of the "it just works with Apple" fandom thing. The more I use the iMac, the more I appreciate that Macs and OS X are just as "fun" as anything running Windows.

A little earlier was a good example. I wanted to share part of the iMac's filesystem using SMB. This seemed easy enough, the instructions on how to do it were clear and, after following them, it utterly failed.

Brilliant.

So I Googled the issue a bit and ran into this handy forum post. Apparently you can't actually connect with SMB if the account you're going to be using to connect with is using iCloud login rather than a separate login.

Brilliant.

Not an obvious thing. Nothing said this was the case. According to the forum post even Apple couldn't help the person who'd been trying to make it work. But at least there was a workaround. All I'd need to do is split the password, have a login for the machine that wasn't the iCloud login and I'd be all good.

I did it, it worked. I could browse the iMac's filesystem from my Windows machine and all was good (I'd been able to do this the other way around for ages and with no problems whatsoever).

Finally got to allow SMB for me

Then I got curious.

What would happen if, once I had this set up, I "unsplit" the password and went back to using the iCloud password to log in? That's when it got really fun.

To do this it asks you for the current password and also your iCloud password. I entered both and...

Finally got to allow SMB for me

Yup. It refuses, every single time, to accept that the iCloud password I'm entering is valid. Trust me, it is. I'm entering the correct password. I can log in to the iCloud website with it just fine. But when I use it to try and "unsplit" my password.... nope.

Brilliant.

I've even tried disabling SMB sharing for my account, and even turning off SMB sharing altogether. This doesn't seem to make any difference. Right now, as far as I can see, now that I've split the password I can't go back despite the fact that there's a method of doing it made available.

Brilliant.


iMac Time Wiggle

Posted on 2015-10-07 11:38 +0100 in Tech • Tagged with iMac, Apple, OS X • 1 min read

Apparently that famous Apple obsession with design doesn't apply to the time display on the OS X login screen (the wake-from-sleep password confirmation one anyway):

Time wiggle

I've never noticed it before. I'm not sure if this came about with the upgrade to El Capitan or not. But now I've seen it I can't unsee it.


El Capitan

Posted on 2015-10-06 13:53 +0100 in Tech • Tagged with Mac, Apple, iMac, OS X • 2 min read

Almost a week ago (yes, I have being meaning to write something down about this and have kept failing to do so) my iMac told me that there was a new version of the OS waiting for me. While this is doubtless no big deal for most Mac owners, this was interesting to me because it's the first time I've experienced an OSX upgrade since I got the iMac.

El Capitan downloading

The download took a while and, while the install had a couple of curious bumps along the way, nothing seemed to actually go wrong.

About to get going

The two main things I noticed were that it seemed to take the installer an absolute age to close down all running apps before it got to doing the installation. The other was that Mac progress bars seem to have a very odd way of calculating things. Often it would tell me that there was (for example) 28 minutes to go, it'd stay like that for 20 minutes, then drop 5 minutes, then appear to finish very soon after.

The final countdown

Mostly though I just left it alone and let it do its own thing. While the whole process took quite a while, it came back just fine (if I'm fair I'm not sure it took much more time than when I upgraded my laptop from Windows 8.1 to Windows 10).

The changes and improvements aren't really that obvious. I think I would say that the machine feels a little quicker in places, but nothing I can really put my finger on. One of the things I do like is the new split-screen facility for full-screen apps. While I don't use the full-screen facility that much I have found the need to split the screen before.

Some of the other improvements I've read about seem to involve things I'm never going to use: either improvements to Safari (Chrome all the way for me), the Mac Mail app (Gmail all the way for me, with Kiwi for Gmail being my client of choice on the iMac) or various iOS-oriented things which are of little use (while I do own an iOS device it's not one I use much).

Overall the thing I'm taking away from this is that the upgrade was smooth, nothing was obviously broken or changed in a way that was confusing (unlike some Windows or ChromeOS updates I've experienced in the past) and I didn't have to do anything that required much in the way of knowledge to keep it all going.

Doubtless that won't always be the case, such is the nature of OS upgrades.


My iMac thinks I'm in Spain

Posted on 2015-09-10 14:44 +0100 in Tech • Tagged with Mac, Apple, iMac • 1 min read

While on the phone earlier I was doing that thing you often do when chatting with someone where you don't have to concentrate on something in front of you: I was randomly clicking around stuff on a machine. In this case I was faffing around on my iMac.

One of the places I landed was in the About dialog, looking at the support details:

Support details of the iMac

Out if idle curiosity I clicked the "OS X Support" link, which opened my browser and took me to Apple's website. Only.... it didn't take me to a part of the site that was that useful to me:

Seems I read Spanish

Yes, for reasons best known to Apple or my iMac, I apparently need my help to be in Spanish. O_o

I could understand this if I had my system set to Spanish, which I don't:

Seems I read Spanish

About the only "non-standard" thing I have in my setup is the date, which I've set to ISO 8601 style rather than the usual UK style. I even experimented with changing that to the default on the remote chance that it was tickling some sort of odd bug in OS X.

So, yes, another wonderful example of Apple stuff "just working" and being good for mortals. Well, for interesting values of "working" anyway.