arrays - Objective-C: Comparing user input with object's instance variable -


i have been learning objective-c while, , decided try , take on little bigger project without real "guidelines" in learning books have got stuck.

what i'm trying helping friend digitalising few documents have, creating searchable commandline-tool these documents.

i think have gotten pretty far, have created custom class documents 3 variable; name of author, number of article , path file on computer (which of course change place have documents stored on computer). have created 2 example documents variables filled in. since documents have 2 properties, numbers , name of author, user may search 1 of these properties. therefore separated input of user either string or int (with of stack overflow post: how determine if first character of nsstring letter ) created array 'author'-variable's of different documents.

this have hit bump: want run through array of 'author' , if author's name match user have put in, open document @ path given @ 'urltodoc'. problem is, instance variable 'urltodoc' not "connected" 'leadauthor'-variable in kind of way (as far can tell). question therefore, how i, after have found match in in array user written, describe 'urltodoc'-variable specific object? (if user typed in jamesson, instance, how describe urltodoc variable value: /users/pinkrobot435/desktop/test1.pdf )

also, if user writes in number, else-statement on bottom (which same thing) should used. haven't written yet though, guess code pretty same, when describing 'urltodoc'-variable.

here code:

my custom class smadoc:

smadoc.h

#import <foundation/foundation.h>  @interface smadoc : nsobject  //two strings, , pathway documnt, purpose of describing document @property (nonatomic) int number; @property (nonatomic) nsstring *authour; @property (nonatomic) nsstring *urltodoc;  @end 

smadoc.m

#import "smadoc.h"  @implementation smadoc  @end 

main.m

#import <foundation/foundation.h> #import "smadoc.h" #include <readline/readline.h> #include <stdlib.h>  int main(int argc, const char * argv[]) {     @autoreleasepool {         smadoc *one = [[smadoc alloc] init];         [one setnumber:123];         [one setauthour:@"jamesson"];         [one seturltodoc:@"/users/pinkrobot435/desktop/test1.pdf"];          smadoc *two = [[smadoc alloc] init];         [two setnumber:124];         [two setauthour:@"marc"];         [two seturltodoc:@"/users/pinkrobot435/desktop/test2.pdf"];          nsmutablearray *authours = [[nsmutablearray alloc] initwithobjects: [one authour], [two authour], nil];          nslog(@"enter want search for: ");         const char *searchc = readline(null);         nsstring *searchorg = [nsstring stringwithutf8string:searchc];         nsstring *search = [searchorg lowercasestring];          nsrange first = [search rangeofcomposedcharactersequenceatindex:0];         nsrange match = [search rangeofcharacterfromset:[nscharacterset lettercharacterset] options:0 range:first];         if (match.location != nsnotfound) {             //the string starts letter , array of authour names should searched through             (smadoc *nsearch in authours) {                 if ([search isequaltostring:nsearch]) {                     **//open file represented urltodoc specific object**                 } else {                     nslog(@"the authour not found, please try again");                 }             }         } else {             //the string starts number , should converted int , array of numbers (which have not yet created) should searched through             int number = atoi(searchc);         }      }     return 0; } 

thanks in avance!

instead of authours array, create array of smadoc objects. then, in loop, each object array have authour or number can match. when right 1 found, can pick urltodoc out of same object.

currently, you're calling each object in array smadoc * when examine it, that's wrong. created array of nsstring * (and you're comparing string correctly) need there real smadoc *.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -