|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Apprentice |
Hi (again),
this time I'm really stuck. I have the following code, which should be - at least the beginning - of a litte routine to prepare the adresses for an address-book -> iPhone sync. But whatever I try it looks like the whole block in
(a_country ~= nil) ifTrue:
[
...
].
seems never to be executed. No msg...log fires, nothing.
"This script gets all relevant contacts"
a_qual1 := BDQualifier qualifierWhereValueOfKey:'defaultGeoAddress.city' isEqualTo:(NSNull null).
a_qual2 := BDQualifier qualifierWhereValueOfKey:'defaultGeoAddress.street' isEqualTo:(NSNull null).
a_qual3 := BDQualifier qualifierWhereValueOfKey:'defaultGeoAddress.postalCode' isEqualTo:(NSNull null).
a_qualifiers := {a_qual1, a_qual2, a_qual3}.
a_andQual := (((BDAndQualifier alloc) initWithQualifierArray:a_qualifiers) autorelease).
a_qual4 := BDQualifier qualifierWhereValueOfKey:'defaultGeoAddress.note' isEqualTo:'automatic'.
a_qualifiers := {a_andQual, a_qual4}.
a_orQual := (((BDOrQualifier alloc) initWithQualifierArray:a_qualifiers) autorelease).
contacts := objectContext objectsForEntityNamed:'Contact' matchingQualifier:a_orQual.
a_index := 0.
a_total := contacts count.
a_msg := (a_total stringValue) ++ ' Contacts'.
sys log:a_msg.
[a_index < 1] whileTrue:
"[a_index < a_total] whileTrue:"
[
a_contact := contacts objectAtIndex:a_index.
msg := 'Name ' ++ (a_contact name).
sys log:msg.
a_defaultRole := a_contact defaultRole.
(a_defaultRole = nil) ifFalse:
[
msg := 'Role ' ++ (a_defaultRole name).
sys log:msg.
a_organization := a_defaultRole organization.
(a_organization = nil) ifFalse:
[
a_address := a_organization defaultGeoAddress.
(a_address = nil) ifFalse:
[
a_total_geos := (a_contact geoAddresses) count.
msg := 'Total GeoAddresses = ' ++ (a_total_geos stringValue).
sys log:msg.
msg := 'making new geoAddress'.
sys log:msg.
a_newGeoAddress := a_contact defaultGeoAddress.
a_newGeoAddress takeValue:(a_address valueForKey:'city') forKey:'city'.
a_country := a_address valueForKey:'country'.
a_country ~= nil ifTrue:
[
msg := 'Country ' ++ a_country.
sys log:msg.
a_country = '' ifTrue:
[
i := 0.
msg := 'Deutschland!'.
sys log:msg.
a_newGeoAddress takeValue:'Deutschland' forKey:'country'.
].
a_country = '' ifFalse:
[
msg := 'Country ' ++ (a_address valueForKey:'country').
sys log:msg.
a_newGeoAddress takeValue:a_country forKey:'country'.
].
]
ifFalse:
[
msg := 'Deutschland!'.
sys log:msg.
a_newGeoAddress takeValue:'Deutschland' forKey:'country'.
].
a_newGeoAddress takeValue:(a_address valueForKey:'directions') forKey:'directions'.
a_newGeoAddress takeValue:(a_address valueForKey:'postalCode') forKey:'postalCode'.
a_newGeoAddress takeValue:(a_address valueForKey:'state') forKey:'state'.
a_newGeoAddress takeValue:(a_address valueForKey:'street') forKey:'street'.
a_newGeoAddress takeValue:(a_address valueForKey:'typeString') forKey:'typeString'.
a_newGeoAddress takeValue:'automatic' forKey:'note'.
"cc deleteObject:(a_contact defaultGeoAddress)."
"a_contact addObject:a_newGeoAddress toBothSidesOfRelationshipWithKey:'geoAddresses'."
"a_contact takeValue:a_newGeoAddress forKey:'defaultGeoAddress'."
objectContext saveChanges.
].
].
].
a_index := a_index + 1.
].
|
||
|
|
Marketcircle Team |
Are you trying to test if a_country is nil or not nil?
And you are using a ~ (tilde) right (I can't tell with this font). |
|||
|
|
Pro |
I assume you are testing to see if a_country is actually set.
Are you sure you need to test for nil for the country? I believe (and could be wrong) that if you have an geoAddress the object will always have a country member and if not set will be equal to the empty string. I'd suggest rewriting the block... drop the test for nil and just test for the empty string case. |
|||
|
|
Pro |
Oh one other thing to try:
This may be a problem between equality and assignment. Try using '==' and '~~' to see if the object is equal to (or not equal to) the nil object. (a_country ~~ nil) ifTrue: |
|||
|
| Previous Topic | Next Topic | powered by eve community |
| Please Wait. Your request is being processed... |
|

