All posts by wendellbeverly@hotmail.com

RNG using Game Kit.

I noticed yesterday when I started getting back into this that the random number generator was throwing an error.

I decided to implement the shuffle distributor from Game Kit, as that will exhaust the entire array before repeating any items.  For example, say I have 100 recordings that I want to randomly play.  By using the built in “random()” in Swift, and passing it the number of items available, each time you call random that is exactly what you get, a random number, between 0 and 99.  So maybe 5 comes up first, then 34, then 11, then 5 again, etc. etc..

This is undesirable.  I have seen (with an array of maybe 50 items) the same number come up 3 or 4 times in a row.  That’s not good, nobody wants to hear the same song, or same joke, or same anything 3 or 4 times in a row.  Inversely, I have also seen a single item take forever to actually play.  So out of those 50 items, the one you wanted to hear might not actually play until the 75, or 100th iteration.  Because it is truly random it might be a long time before picking that 1 item.

This is why I decided to use the shuffled distributor (GKShuffledDistribution) from Game Kit.  This is genius.  This will also select a random item, from 0 to 99 (or whatever you have), yet it won’t select the same item again until all items are exhausted.  So once #34 comes up the system will not select 34 again until the rest of the items in the array have been used up.

The error I was getting was because the app only had a single item in the array, and the bounds were set to be from 0 to count of items – 1. Theoretically I would think “between 0 and 0” might return 0, it doesn’t seem to work out that way, or I’m just interpreting the information incorrectly.  Once I have a few items in the array, it works fine.  My intent is to have a pre-loaded number of items in the array when the app is installed so the error should never pop up, but I will be keeping my eye on it, as well as testing to make sure it does indeed cycle through all possibilities before replaying anything.

Next, to finish the “launch” screen and make that presentable.  This should only show for a second or two while the app loads, but should be something decent looking that shows what the app does or is about.

Until next time.

Getting back in!

It’s been a while since I looked at or did any programming in iOS and Swift.  I’m going to make a point of getting in and programming something (at least that is the goal) once a day.  Even if I just add a single line of code, or jot down ideas for a new app, something has to be done.  I like programming and hope to build myself a nice portfolio of apps available in the Apple App Store.  I just plague

Today I am revisiting my Daily Blessing app.  I had completed programming it (for the most part) and need to record everything that will go into it.  That’s just a matter of getting over being self-conscious about recording my own voice.

That and I plan on trying to promote my other app, “Daily Dose of Humor“, that starts with something like 100 recorded jokes for your listening pleasure (all G Rated), and every day that you launch the app it will download another joke.  You can also record your own and store them locally, and if you are logged into iCloud they will save to the cloud and once approved will be made available for anyone to listen to.  Pretty cool right?

More to come.

UILabel and text.

In an upcoming app, I put a couple UILabels on, and populate the text from a database.  I then rounded the corners to make it look nicer, and was able to get the labels to auto-size so they adjust according to how much text is in there.

However, even though rounded corners look nice, it makes the edges of the text cut off.

I spent quite some time online looking for a way to, say, expand the label text area by 20 points (kind of like pixels).  I found all kinds of ways to make an auto-sizing label in code, but I didn’t need that since I had already done that through the Xcode interface itself.

I gave up, and instead just added 3 spaces before and after what I add from the database, and it worked out perfectly.

Gotta remember K.I.S.S..  Keep It Simple Stupid.

LAUNCH (again)

It has been some time since I posted to this site.  I’ve been posting (although infrequently) to Facebook, but think I’ll come back to this and do posts here again.   I can always push from here to Facebook.

I completely rewrote my “A Dose of Humor” app and it is not “Daily Dose of Humor”.  The rewrite served two purposes:

  • change from Objective-C to Swift.  Swift is the new language (relatively new anyway) from Apple for iPhone development.   Might as well keep up to date with the current language.
  • secondly, the database back-end that I had used originally was done in Parse.  Parse was a fantastic tool to quickly configure and use a cloud database.  Parse was purchased by Facebook, and not too long after it was purchased it was announced that it would close down.

So, with the shutting down of Parse I had to find another cloud database back-end, and I chose to write this in CloudKit, which is Apple’s native cloud database backend.

So here we are, my new app has been released into the wild, check it in iTunes on the App Store.

View on App Store

 

 

Voodoo Doll progress.

This is a rough draft (very rough) of the Voodoo Doll app I am working on. I got the coding to always point the pins towards the doll no matter where they are on screen, and removing your finger from the screen drops the pin in place.Next steps for me are to:
1. Make visually attractive dolls and pins to use for this. 

2. Enable some way to put a person’s actual face on the doll.

3. Interact with various social media outlets to enable posting of your “victim”. 

  

Voodoo Doll App

I am working on a Voodoo Doll app, that will allow you to put pins into a Voodoo Doll (both feel-good and feel-bad pins) that will elicit a response from the doll.

You’ll be able to name your doll, and if all goes according to plan, you’ll be able to take a face from a picture on your iPhone to place on the doll, and then really “stick” it to them.

After you are done, you’ll be able to snapshot your finished product, be it with pins of love or pins ‘o pain, and send them along, post them to Twitter, Instagram, Facebook or just text it.

I’m pretty jazzed about this.  It is taking me in directions I haven’t gone in an app yet, and should be lots of fun.

 

Apple WatchKit and Me.

I've been following Ray Wenderlich (www.raywenderlich.com) and Steven Lipton (in the iOS-Developers group in LinkedIn) for some time, and recently went through some tutorials by both of them for WatchKit, Apple's addition to XCode that allows creating Apple Watch apps (no, it's not an iWatch) that piggy back off of your main app.

I tried adding WatchKit to my Dose of Humor app, but because I originally made the app before WatchKit was available, XCode doesn't like it at all, and is fraught with errors.

So, what I think I'll have to do is create a new project and include WatchKit in it, and then either copy/paste my code over from my original project in Objective-C, or rewrite it in Swift.

The last couple of tutorials I went through with WatchKit used Swift, and I think I could definitely get used to that. It's more user-friendly in terms of language and syntax, which is good for me. Anything that helps me get my concepts and ideas transposed to an app is a good thing.

I think for the Watch app I'll go for super simple. Instead of having to get the joke of the day directly on the phone, I'll enable that to be done with the app. At least that's the plan. Without having done it yet I have no idea what parts are even possible. Ideally I would want the Watch app to force the phone to download todays joke, and then play it over the watch. With some simple animation maybe that mimics what is on the phone.

That's my mission today. Get started with a new project and get it functional for what the app has/does now, then maybe take a look at WatchKit and see what magic I can make happen there.

notsoloud

 

EUREKA!!!

I’d been having trouble populating a UITableView with the entire contents parse data in my iOS application.  Come to find out that when using Parse and referencing the objectId field, that you need to use dot notation and not by referencing the field like the other ones.

So, use this:  parseData.objectId
Instead of:  parseData[@”objectId”]

Who’d have thunk it.
Same when adding to the local data store.  I download the records from Parse and iterate through them to search the local data store.  If found it should do nothing, if not found add it to the db.  Because of the dot notation on the objectId field it would never find it because it search on <nil>.  So the same records got added over and over again.  All the other fields get added using the parseData[@”dataField”] type of reference, which threw me.

Finally, once I figured out to use parseData.objectId instead, it added it correct and found it the next time I launched it so there is only a single entry for it in the local db.

(it was at this point I laid my finger between my lips and made googly noises)

Now just have to format the cells in the table view, make the appropriate actions once the cell is tapped, and I am all done.

It is still a little slow at launch as it searches all the files and tables to add locally.  I’ll have revisit that, maybe only pull down the file name or some other reference to make it speedier.  It’s not horribly slow, but I would like it to be faster.