eSpecializedHow to use Objective C properties Properly

December 6th, 2011 No comments

In programming for iOS devices, many many people get properties wrong.  It is true, there are many ways to use them.

The retain property is probably the best example I can think of.  Some objects when alloc’d and init’d, create a retained object.  Some other + functions create autorelease objects in the iOS library.  I still have problems with these at times, due to the learning curve, and finding other peoples library’s do not follow the same conventions or template that the iOS libraries do.

 
 
#import <Foundation/Foundation.h>
 
@interface Properties : NSObject {
NSMutableArray *myArray; //optional, properties now create the class object from the synthesize statement in xcode 4 and later.
}
 
@property (nonatomic, retain) NSMutableArray *myArray;
 
@end
 
#import "Properties.h"
 
@implementation Properties
 
@synthesize myArray;
 
-(id)init
{
self = [super init];
 
if (self) {
//here we assign the class object myArray the new alloc/init'd instance.  This alloc/init'd instance comes with a retain value of 1
myArray = [[NSMutableArray alloc] init];
}
 
return self;
}
 
-(void)dealloc
{
//here we use the accessors to release the contents.
self.myArray = nil;
 
[super dealloc];
}
 
@end

And that my friends is how to use a retain property.  If you set it = to anything else,  use the class object if what is returned is already retained (mutablecopy, copy, alloc/init).  If what you use is autoreleased (+ methods),  use the self.myArray to obtain the object and set a retain value on it.

I realize I don’t show assign for objects or others. Assigns you can always use the accessor methods, you must retain or release objects as needed with assigns and watch them just as tho you were using a class object.

If your App Delegate has your music, sound effects, graphics, opengl context etc retained. All subclasses (main menu, game, prefs etc) should only reference those retained objects with an assign.

Specifying autorelease;
You can change a retained object into an autorelease object. Once all objects no longer retain it, it is dealloc’d.
1. Do not add an object to a autorelease pool twice.
a. Any object that comes from foundation which has a +shared by it, returns an autoreleased object. Read the documentation to ensure this is the case. Adding such an object to autorelease pool will introduce bugs and cause untraceable crashes.
b. For libraries made by other people, double check their code if its available, sometimes people do not return an autorelease object for their +shared methods.

2. Do not set a property that is retained, self.myarray = to a [[NSArray allc] init] retain]; this will result in improper retain counts. Count those retains, one by the property, one from alloc/init, and an additional one at the end with retain. 3 retains there.

I hope this helps you out, always use leak detector AND analyzer to help flush out bugs introduced using properties, and your retain counts.  Hold down on the Run button, and you will get profile and analyze.  Run analyzer first to fix the code problems directly,  and then use profiler to get extra retain bugs you missed.

 

eSpecializedRFC: Daylight Savings Time – for all integrated devices

November 20th, 2011 No comments

Subject Matter: All clocks, computers, portable devices, cell phones, at current time devices require firmware updates if supported to have new dates for day light savings time adjustments.
It would be far easier for all new designs to incorporate the ability to adjust the Day light savings time fall back, spring forward dates.

At current I have a few devices that cannot be updated, and have no interface to do so. At least 2 more sophisticated devices that run off nuclear decay time, and their date systems are hard set.

So I am throwing this out there, if you plan on releasing a device designed with any kind of real time clock (RTC) that has DST support in it, ensure to allow adjusting the dates for fall back, spring forward.

It would be far easier to just allow the consumer to adjust the hour + or – by one hour, than to include a DST setting.

My home thermostat has a old DST setting in it. No interface is included either by menu, or usb to update the device. It is quickly becoming obsolete.

Categories: MCU Assembler Robotics Tags:

eSpecializedbCandied and SudokuGeek updates

November 19th, 2011 No comments

Unfortunately, its been difficult to work on updates right after my surgery. I am in high hopes that this may fix my sinus issues.

Besides all those things.. I believe that the bCandied update is ready at last to go out. I had to re-port half the updates to ensure no bugs appeared. I got the most important ones done for now.

SudokuGeek -> making it harder. Now this may be a challenge. I think I have a way figured out of inserting xwings, triplets, twins, into the puzzles to make a “Very Difficult” category.

Getting back to the Robot >> wow when I cracked open the code to work on it, I found I was a bit muddy minded to work on it. I have a new AVR32 bit controller, and a Venus GPS module. I will build the RC Rover into my Traxxas Summit. Now that should be an excellent robot rover! All terrain, way point capable. I’ll be writing it entirely in C if any one asks. Assembler resources for the AVR32 MCU’s is limited.

eSpecializedSparky Bot

November 2nd, 2011 No comments

I’ve been working on some extra after hours project; Sparky Bot.

Before I realized it I was wanting to develop the bot into a mini sumo bot. I lost focus on my vision of just getting the bot to move around and dance.  Its neat how hobby’s change and morph with desire to do more.

The idea of some competition, of building my own sumo ring, and of forming both robot chassis’s into sumo bots won’t be forgotten any time soon. Still I had a task to finish, and here are my results;

Tasks;
1. Finish the bot build I had begun a long time ago.
2. Get the robot to move around, sort of like a dance,  as much as a wheeled robot could be made to do so.
3. All code to be made in Assembler for the AVR
4. Movement would utilize counts from the quadrature encoders. The counts would use two interrupt pins as input to count up a distance.

After much pouring over documentation, assembler how-to and work. I came up with a working robot that does just these tasks.  My list is far longer but this is a good checkpoint before I make improvements.

Image Showing the AVR Mega32

Image Showing the AVR Mega32

Right Profile

Right Profile

 

Left Profile

 

Future of the design;
1. Get weight limit to within 500 grams for the sumo bot competition.
2. The servo wheels are a little too wide at the moment, I need to put the servo’s on the inside of the bot to meet the 10CM width and length of the bot.
3. The back with the caster wheel has to change in length to fit the 10 CM length limit.
So this all means that the batteries have to be repositioned. The servo’s instead of mounting on the outside, have to be on the inside. The batteries will have to fit above the servo’s.
Additional parts needed to add are the line detectors so the bot won’t roll off the table.

Lessons learned;
Controlling servo’s is nothing simple or easy, but requires thinking about what is really happening with the timers and when/how to adjust the PWM out to them in the AVR.

The “center” no roll setting for these continuous rotation servo (aka Gear boxes) floats. So the bot will have to be smart about it, and that requires some extra coding.  Since the quadrature encoders have a direction output, I can utilize that to make adjustments on the fly to the standing still code, to ensure the robot stays stationary.

Finally roll speed, the speed needs to be equal on both sides to more or less move in a straight line. Some extra code for this will be needed too.

Finally the movie;
http://youtu.be/3k2yxaxhIGs

 

Categories: MCU Assembler Robotics Tags:

eSpecializedUIScrollView doing the impossible – set contentSize in IB

August 17th, 2011 No comments

I’ve read often that its not possible to set contentSize in Interface Builder.

Well I’ve found a hack around so to speak.

Lets go with dimensions of the touch and phone devices.  320×480 is their screen display size.

Assumptions; your UIScrollView is all wired up to your class file.

1. UIView is set to the dimensions you want to edit at first (say 320×520)

2. Scrollview -> same as UIView, but all autosizing items enabled locked to each edge.

3. Edit the Scrollview the way in which you want it.  Now in the UIScrollview attribute inspector, deselect “Autoresize Subviews”

4. Now comes the time to change the size of the UIView. so select it, and set it to the screen dimensions.

 

5. Now in your viewWill/DidAppear method, use these lines

        CGRect newFrame = self.view.frame;
        CGSize newSize = CGSizeMake(self.view.frame.size.width, scrollView.frame.size.height);
        [scrollView setContentSize:newSize];
 
        [scrollView setFrame:newFrame];

This accomplishes 2 things;
It grabs the frame height and sets it into the contentSize. This will allow scrolling.
The UIScrollView’s Frame is set to be the UIView’s frame.

Debug;
If you fail to deselect “Autoresize Subviews” in IB for the UIScrollView. When the Frame Size adjusts, so will the content, which is not the desired effect. So Just remember, autoresize can be a disaster for UIScrollView in some cases, and an advantage in others.

Categories: iOS Dev Tags:

eSpecializedXcode 4 Connecting file owner to app delegate

August 4th, 2011 No comments

http://stackoverflow.com/questions/6170393/connecting-file-owner-to-app-delegate/6949566#6949566

Posted on Stack over flow, how to connect the delegate to the files owner in the dock.
Since the Xcode 4 dock is usually hidden, this much needed part, to connect a delegate of a view to a file, is very needed. And probably asked about and has people frustrated to an end.

So basically, select an XIB file, the Dock appears second pane from the left.
open up the Xcode 4 dock, which has a small triangle pointing to the right in it on the lower part of the bar.
You will see “Files Owner” pop up, and you can open up the view and make connections there.

Categories: iOS Dev Tags: , , ,

eSpecializedBean Diet – Day 40

July 12th, 2011 No comments

I saw my lowest weight today at 258.2lbs on the scale.  This is about 4 lbs in 40 days, but it is an improvement over 262 from the original highest weight.

Concerning this recipe; http://www.foodnetwork.com/recipes/alton-brown/the-once-and-future-beans-recipe/index.html

This has me wondering what happened the first round making this recipe of beans?

Well we made the recipe of beans differently.  We used White Great Northern Beans from Walmart.  We used low sodium bacon in the first batch from Costco. Also at the very end of cooking, is when I added the Cayenne pepper, black pepper, and salt.  And I only use the sea salt while my wife used kosher salt in our 2nd batch.

We have obtained a 20 lb bag of Great Northern white beans from Cash and Carry.  We plan to stick to the beans.  I am hopeful that these Great Northern white beans are the same as what we got for the first batch. Soon all will be told.  There are so many sub species of beans, it would be hard to believe that it may just be the first bag of white beans we got that caused such dramatic results.

Is it the beans, or low sodium bacon that makes all the difference?  Could salty food prevent weight loss?  It doesn’t appear to be in the list of causes, maybe just water retention issues? http://www.water-retention.net/causes-of-water-retention/

So on to more testing with the recipe.  Fortunately it is not boring to eat it once a day, and just for bfast.

I also recall adding in lots of cans of beans here and there to add variety.  So I will be sure to do that.

Categories: Health and Dieting Tags: ,

eSpecializedBean Diet – Day 29

July 1st, 2011 No comments

Some catch up.

Yesterday, Beans in the AM


And the weight in has me at 255.6lbs

Lunch was left over food from eating out, a few nacho’s with steak and some flauta’s.

Dinner was home made mixed pork, potatoes, and carrots, white basmati rice.

 

Categories: Health and Dieting Tags:

eSpecializedBean Diet – Day 28 – Lessons learned

June 29th, 2011 No comments

My wife and I are 4 weeks into this.

My thoughts during today’s walk were; stick to the beans.  So I am going to forgo most other foods in favor of beans strictly.

If this is a bean diet, lets do it that way!  I think in a prior post I was stating to adopt this ideal too.

For the past week I have eaten beans once daily, if not twice.  The decline did not start occurring till we started in on the White Great Northern baked beans Sunday June 26th.  Since then, each day we have seen about 0.3lbs disappear daily.

Why the bounce back up then now climbing steadily down?
1. Exercise builds muscle mass which is heavier than fat.
2. We changed to other beans to try it out, see if the losses continued.  This was at about the same time. We found with other beans you could get hungry again much sooner, and could eat much more than on the white baked beans.

So going back on my word earlier, I walked to McD’s and got myself an Egg McMuffin. :) 300 calories – 275. so just +25 calories,  + coffee cream and sugar = 35 more calories.  only drank half (they changed their coffee, its not tasty any longer).

So 60 calories this AM left to burn!  Beans is on the menu for Lunch.. I have an old DOS program from the 90′s that lets you combine ingredients and measure the calories better, so I will use that and post later the info on calories more accurately per cup of beans.

Finally todays lowest weight seen;
Seems I cannot get a good image of the scale lately.  So a few times before this I saw 256 several times, then 255 several times.  We will just call it 255.5 lbs then.

 

Categories: Health and Dieting Tags:

eSpecializedBean Diet – Day 25

June 26th, 2011 No comments

We got some more baked beans cooked again.

After days of seeing increasing higher weights.  After just some of the beans last night, my wife is nearly back down to her max weight loss.  How odd really!

What is it about baked beans that makes them so special? Or for that matter the white bean variety in particular? Off to Wikipedia to find out more.

http://en.wikipedia.org/wiki/Phaseolus_vulgaris

White Beans: Consumption of baked beans has been shown to lower total cholesterol levels and low-density lipoprotein cholesterol.[15][16] This might be at least partly explained by high saponin content of navy bean. Saponins also exhibit antibacterial and antifungal activity, and have been found to inhibit cancer cell growth.

Saponin leaves room for future blog updates. Look forward to more updates.

 

Categories: Health and Dieting Tags:

eSpecialized Blog is using WP-Gravatar

Page optimized by WP Minify WordPress Plugin