yesterday I played arround with selectors an was quite satisfied with the results. Suddenly I stumbled because of arguments or return values that were more or less atomic types and obviously not classes. Perhaps it gets clearer, if you see my code:
- Code: Select all
Declare Function "NSString" + (id)stringWithString:(NSString *)aString
Declare Function "NSString" - (BOOL)hasSuffix:(NSString *)aString
' - (NSString *)stringByAppendingString:(NSString *)aString
Declare Class "NSNumber"
Declare Function "NSNumber" + (NSNumber *)numberWithInteger:(NSInteger)value
' to capture the Log messages in a file
' invoke the app from commandline and redirect stderr to file via <appname> 2> err.out
Dim myString As NSString
Event AwakeFromNib()
Dim myLength As Integer
Dim myNumber As NSNumber
Dim myBool As Boolean
Dim mySuffix As String
Dim myObj As id
Log("AwakeFromNib")
myString = NSString.stringWithString("hund katze maus")
mySuffix = NSString.stringWithString(" aus")
myNumber = NSNumber.numberWithInteger(1)
Log(myString)
Log(myString.PerformSelector0("uppercaseString"))
Log(myString.PerformSelector0("description"))
Log(myString.PerformSelector0("capitalizedString"))
' this construct should help to capture the return value, because it is
' declared to be of id type
' but NSString's length returns a (NSUInteger) which is basically a
' (unsigned int)
' but this doesn't work
myObj = myString.PerformSelector0("length")
Log(myObj)
' check to see, if NSString instance answers to hasSuffix message
Log(myString.RespondsToSelector("hasSuffix:")) ' it responds!
' called directly it returns the correct result
Log(myString.hasSuffix(mySuffix))
' myObj = myString.PerformSelector1("hasSuffix:", mySuffix) ' this doesn't crash, but doesn't produce results
'
' Log(ClassName(myObj))
' Log(myObj)
' this crashes directly - return value is (BOOL), another atomic/non class type
Log(myString.PerformSelector1("hasSuffix:", mySuffix))
Log(myString.PerformSelector1("stringByAppendingString:",mySuffix)) ' it works for NSString as result, but not other types
End Event
Perhaps this is a general problem, but perhaps I (again) miss some common knowledge
Regards
Udo