Dear friends,
In my previous post I running into difficulties because my code in AppDelegate is too long, so I am trying to break it into classes…
It seems I have made good progress, but I still need assistance.
The attached app is an example for handlers to check the consistency of “tax id numbers” which follow a different algorithm for each brazilian state.
The taxing id number in the example should return true, but it fails since it can not understand the line “count of characters in string”.
The handler works fine in AppDelegate, but fails in helperClass.
I would like also the helperClass to increment the properties errorCount and erros (just a string listing all found errors) in the AppDelegate, but I have no idea how it can be done.
I also have no idea if the blue cube for helperClass is needed to be visible in MainMenu.xib, and why it is not shown there.
You can download the project here:
https://files.me.com/fundidor/9bohpm
I am running Lion and xCode 4.2
Thank you,
Well the first thing I notice is that
tell helperClass to set theInstanceName to alloc()'s init()
will not work because the variable theInstanceName does not exist anywhere and you cannot tell another class to create a variable.
Also you have linked up the classes incorrectly, where you have the property helperClass you have linked it to files owner and put current application everywhere, the correct way is to use helperClass’s [your message] and to create object class in IB similar to the blue cubes on the left. Simply drag a new one from the right side palette to beside the other cubes, then click the new one and then go to the identity inspector on the top right and change the class to helperClass, then make an IB link from the helperClass property to the cube, it should work as it is but I recommend you delete 'current application’s.
Your other problem was due to ASOC coercing strings for you in order to send messages (i believe) I have fixed it like this:
on filterAlgarismos_(astring)
---updateStatusMessage_("Filtrando algarismos em " & _string)
set newList to {}
repeat with i from 1 to the count of characters in (astring as string)
if algarismosValidos contains character i of (astring as string) then
set end of newList to character i of (astring as string)
end if
end repeat
return newList as string
end filterAlgarismos_
regarding that and the rest here is the fixed project https://files.me.com/imadrichard/g5wrqd
I commented out the instance thing which I messed about with and abandoned, if you tell me what you were trying to do I can help.
Richard
In addition to adding the blue cube, setting its class to helperClass and connecting the property helperClass to it as Richard said, I found two other problems in the code:
in your filterAlarismos method, _string is an NSString so you have to coerce it to an applescript string for it to work. I added the line “set _string to _string as string” to do this.
Second, in the if clause that starts your example, you have another coercion problem: “else if UF is “RJ” then” needs to be “else if UF as string is “RJ” then”
Ric
Oh I also forgot that to fix it I had to use coercion in the ifs as Ric said for it to work, good point! I didn’t add it to any unnecessary parts of the if only the test case so please add ‘as string’ to all sections.
Hi Richard,
Thank you for being so kind.
I have revised every step you described, and now I get in my console:
2011-08-03 13:04:32.096 helperClassExample[46425:707] *** -[helperClass alloc]: unrecognized selector sent to object <helperClass @0x400169ca0: OSAID(8)>
2011-08-03 13:04:32.129 helperClassExample[46425:707] *** -[helperClassExampleAppDelegate applicationDidFinishLaunching:]: *** -[helperClass alloc]: unrecognized selector sent to object <helperClass @0x400169ca0: OSAID(8)> (error -10000)
Can you please take another look at this updated version??
Here: https://files.me.com/fundidor/fn3wpv
Thanks!
Here is another link, this one has been updated to rdelmar’s comments…
Here: https://files.me.com/fundidor/e6po01
thanks!
You need to get rid of the first 2 lines in your applicationDidFinishLaunching method – putting the blue cube in IB creates an instance of your helperClass, you don’t need to do anything in code.
Also the first line in your helper class’ method, check_ie_(IE, UF), doesn’t work. It should be: log IE’s |class|().
Since I am running in XCode 3 (under Snow Leopard), the way I have to test your code is to start a new project and copy the code into it, so I’m not sure that everything that works for me will work for you, but when I run my program with the changes I suggested above, I get:
2011-08-03 09:24:32.321 TaxChecker[3350:a0f] NSCFString
2011-08-03 09:24:32.340 TaxChecker[3350:a0f] helperClass says: true
2011-08-03 09:24:32.341 TaxChecker[3350:a0f] AppDelegate says: true
Ric
Hi, I am positive the version I sent works under Lion. I will look again.
Mine (one I sent) says this:
Now I’ll check yours.
…And I can’t even get it to compile, it says line 612 is wrong.
Great!!!
It seems I am getting back on the road to developing…
Thanks, thanks so much dear Richard and rdelmar!!!
Fixed? Or do I carry on with your most recent offering?
Well I found the problem to the compile was a missing bracket in the test case to accompany the one by count.
and your errors are from this: tell helperClass to set theInstanceName to alloc()'s init()
Why are you trying to do this? I don’t understand, as I have already said in my first post.
Dear friends,
Please take a look at this version:
here: https://files.me.com/fundidor/ibqb83
The taxing ID number should now return “invalid” or false.
But I would like to increment the variables (properties) errorCount and erros (a text containing all errors found), under AppDelegate.
Can this be done?
How?
How do you mean increment these things?
Do you mean a repeat which uses a different IE and UF each time, and do you also want to collect the errors for each of these?
I want to collect the errors and the count of errors in the properties erros and errorCount under AppDelegate.
I have 5,000 lines of code, and many handlers like the example.
Once the app is run, I want it to prompt the user with all found errors…
I think the best way is one you might have partially set up. For the helperClass and others like it you need to set up an error property (a list). Every time an error happens add to the list. Where you have a return line e.g. ‘return false’ you should use e.g. ‘return {theListOfErrors, false}’ -that will allow you to communicate back the errors, I’m sure you can work out the rest, including a count operation.
Yes, good idea.
I thought of that.
But isn’t there any way I can increment a variable in AppDelegate, from another class?
I ask just for learning purposes…
suppose in classA you have a property named “one”
a feature of Objective-C is the getter and setter of this property to be like the following in classB
classA’s one()
classA’s setOne_(theValue)
for the setter notice the initial capital is added
Richard,
In Objective-C, to get a property from some class, you have to import the header file first. In ASOC, do you need to “import” a class? If so, I imagine that it would be through a property. But still I am clueless.
No, you don’t need to import anything. In the example we’re working on here, Bernardo has a property in his app delegate class called helperClass which is connected to the blue cube in IB that is an instance of his other script, HelperClass. To log a property (erros in this case) in that class from the app delegate the only thing you need to do is:
log helperClass’s erros()
You can do it with or without the parentheses after erros. Without the parentheses, you are accessing the property directly, whereas with the parentheses you are accessing it via its getter method.
Ric
Actually, the getter is used either way.