I’m surprised by this for what seems an otherwise very structured language. You can extend existing classes via extension String and add whatever methods you’d like onto them.You don’t have to worry too much about this, the compiler will warn you and enforce that you put these attributes in the right places. exposes the swift function/class to the objective-c side of the world.Here’s a < 50 line implementation of a simple stdout log. There’s an open-source package out there, but not having it included with the stdlib is crazy to me. There’s no built-in logging library with levels.This makes sense since swift is strictly typed, but makes fiddling with data structures a PITA. There’s a built-in JSON decoder, but it requires you to describe the incoming JSON payload as a struct.You’ll end up needing a community package and using the swift CLI tooling is nice. I found later on that it’s better to just set up your application using Package.swift, even if it’s small.Both of which are a pain for a simple utility. There’s a community built package manager, but it requires that you (a) have a Package.swift and (b) use a specific source code structure.Specifically guard is useful for unwrapping an optional and assigning the unwrapped variable to something that can be used in the outer scope.It’s like unless in ruby with some special scoping properties. The guard statement is explicitly used to return early.Below are my notes from learning swift and macOS development. I haven’t touched macOS development in years and hadn’t done any Swift development before. Here are the two repos with the resulting code: With a clear goal in mind for this learning project, I was able to get started and build this out. Run CLI tool as privileged (in order to mutate /etc/hosts).No UI, maybe build a simple REST API that could be tied into my beloved Raycast.Support blocking urls in google chrome and safari.This will enable things like blocking news or shopping search on google. ‘Partial match’ means (a) anchors are excluded and (b) the configured block url must only be a subset of the url on the browser in order to be blocked.Allow both hosts and partial match urls to be blocked.Add a ‘first wake of the day’ trigger that I can tie into clean browsers and todoist scheduler.Replace sleepwatcher by configuring script execution on wake. Allow different blocking configuration to be scheduled.Allow configuration to be easily set using a JSON file.My goal is to layer on top of the existing host-based system that has been working great and add another layer of focus tooling: Sleepwatcher (cli tool) is dead and requires some manual set up to get working.If I remove a host it will not automatically get blocked unless I sleep and wake the computer.I can’t block specific URLs, only hosts (focus app couldn’t do this either).However, there are some issues with the host-based approach: They didn’t fix the bug and I abandoned using it and instead switched to a host-based blocking system which has served me well. But, years ago it started glitching out: sucking up tons of ram and freezing my computer. It blocked websites and apps on a schedule.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |