Starting a New Project

I’m moving on from QR Codes. They were fun to play with. And I also got to see some of the Core Graphics and Core Filter APIs. I’ve also decided that the CoreX stuff will need a thin abstraction layer for proper usage in Swift. For example, instead of using a CFDictionary, I want to use a native Swift dictionary.

My real worry with starting a new project is failure to complete. I have a real desire to get this one onto the App Store. If history is anything to go by, the odds of that are grim. Even so, I thought I would go ahead and blog about the process I am going through. Maybe someone will read it and give me ideas.

The new project I have in mind has been given the code name Leonardo. I actually hope to make that my product name in the App Store. It’s an OS X project that will be implemented in Swift. Obviously I will have to use AppKit and some of the Core Foundation and other frameworks. Hopefully I can structure the code so that the majority of it is straight up pure Swift. The reason to do this is I like Swift a heck of a lot more than I like Objective-C. I may even like it more than C.

So anyway. The first step in creating a new project is to have a mission statement, so to speak. It’s the goal of the project. It’s the thing that should not be lost sight of. I’m using TextEdit to write down my notes on the project. Here is the statement:

Mission Statement
Mission Statement

 

My notes include more than the mission statement of course. I have a strategy for achieving the goal, if I can indeed achieve it. A fundamental part of the strategy is the file format itself. It needs to contain the information acquired from the user via the UI. I’ve decided to use a bundle of JSON files. There will also be bitmaps stored in the bundle if they are imported into a project.

The first step in my project will be rather peripheral. I will be working on importing an SVG file, which is in XML, and converting it to JSON. I will also go the other way. On top of that, I will render the SVG file to PNG, JPEG, and PDF. I will also support SVG output. I’m not sure that SVG supports all the features I have in mind though. So SVG output may lose information or get really complex to create the data for rasterization.

XML is actually kind of complex to parse, unlike JSON. I will almost certainly use the NSXMLParser class to do the work for me. While I would love to do the job in pure Swift, it’s work that is not core to the project.

JSON may not be compact like a binary format, but the human readability is a great benefit. There are also wins in using JSON. To give a hint at what I mean here, Lisp is written as a Lisp data structure. Code is data. JSON is also well defined and has all the necessary elements in it to describe an image.

I do worry about recording all the user input taking up too much memory and creating very large files. I’ll have to do empirical testing to see if that will be the case. The part that will take up the most space will be the free hand drawing. Basic shapes that are part of SVG and Quartz Core won’t present such problems.

Another concern is processing the data fast enough to give the artist the impression that he is manipulating pixels rather than vector data. There is more work here than simply pushing pixels around. Again, I do not know if this will be a problem or not. Humans think in millisecond time scales at best. The CPU clock is clicking away at over a billion times per second. That’s about a million times faster. Also, the typical screen refresh rate is only 60Hz on an LCD display.

I should be able to beat that window.

This is actually an ambitious project I am taking on. There are already programs out there that allow users to do all sorts of fantastic drawings. I’m looking for a different approach that I hope will prove to be advantageous over traditional bitmap drawing programs.

Yes, Back To Basics

The problem I’ve been having with the UICollectionView has been solved by vacawama on Stack Overflow. The question I posted, along with the responses I got are here:

http://stackoverflow.com/questions/29715269/uicollectionview-not-sized-or-rotating-properly/29719673

It has been pointed out, correctly, that my manner of asking the question was not ideal (paraphrasing here). I won’t excuse myself. Still, I couldn’t think of any other way to do it. I had no idea where the problem lay. I didn’t think pulling from GitHub would be a huge burden. I was probably wrong on that point even though vacawama took it up.

Now I can go back to the app that really matters and fix the collection view there. I’ve also committed the fix, with credit, to GitHub. So anyone with any interest in a modern way to implement Apple’s CollectionView-Simple example in Swift 1.2 can pull down that project and play with it.

It’s something of a stress relief that the problem was solvable. I just wish I knew how the view options got screwed up.

Back To Basics?

I’ve been working on a simple (relatively speaking) app that I thought would be useful at conventions and such. The key UI element in this app is a UICollectionView. Apple has a demo app for using it called CollectionView-Simple. It works just fine as given. However, I’m using Swift 1.2. So I translated the example with a project starting from scratch.

It doesn’t work.

OK, it sort of works. But the collection view does not draw properly. It also draws differently on different devices. But the thing that is really bugging me (apart from not being able to solve this little issue) is the device rotation. The view is supposed to redraw itself to fit the rotation. It’s not doing that.

To be honest, this is driving me mad. I’m sure I’ve looked at every option in the storyboard editor (Interface Builder) to make sure that all the settings are the same as in the demo app. I can’t find a discrepancy. Except for rotating the device to a different orientation, the app works properly (so far as I can tell).

The WWDC is coming up in June. It would be nice to have my app on the iTunes store by then. But I must confess that little issues like this really do drag me down mentally. If there is anyone out there who can figure out the issue, I sure would appreciate it.

Here is the project on GitHub.

https://github.com/DavidSteuber/CollViewSwift