xcode - linking dictionary to custom initialiser terminating - reason: '-[__NSCFArray isFileURL]: -


please patient im nuubie @ i'm writing custom init first time, sentance01text loads fine know plist reading ok :) cant seem sentance01timing timings work ><

this method should pass sentance01timing typed user objectforkey should load relevant array audiointervals array

at moment i'm using nsstring access dictionary , pass array audiointervals seems wrong , causes error anyhelp appreciated. dont understand why worked text not this? terminating - reason: '-[__nscfarray isfileurl]:

probably im doing dumb >< please if can ps having use old mac (my nice 1 being repaired @ moment - using non arc - updating code when nice mac back, keep in mind why im not releasing objects @ moment...)

helloworld.m

#import "helloworldlayer.h" #import "textwithaudiohilight.h"  @implementation helloworldlayer  +(ccscene *) scene { ccscene *scene = [ccscene node]; helloworldlayer *layer = [helloworldlayer node]; [scene addchild: layer]; return scene; }   -(id) init { if( (self=[super init])) {     textwithaudiohilight *pagetext = [[textwithaudiohilight   alloc]initwith5:@"test words here,\nmore words, more words.."                                                             sentance01timing:@"timingsen01"                                                               withsoundnamed:nil];     [self addchild:pagetext]; } return self; }   - (void) dealloc { [super dealloc]; } @end 

textwithaudio.h

#import <foundation/foundation.h> #import "cocos2d.h"  @interface textwithaudiohilight : cclayer {  }  @property(nonatomic,retain)nsstring *sentance01text; @property(nonatomic,retain)nsstring *sentance01timing; @property(nonatomic,retain)nsstring *soundnamed;  -(id)initwith5:(nsstring *)sentance01text sentance01timing:(nsstring *)sentance01timing withsoundnamed:(nsstring *)soundnamed;  @end 

textwithaudio.m

#import "textwithaudiohilight.h"  @implementation textwithaudiohilight  @synthesize sentance01text = _sentance01text; @synthesize sentance01timing = _sentance01timing; @synthesize soundnamed = _soundnamed;  -(id)initwith5:(nsstring *)sentance01text sentance01timing:(nsstring *)sentance01timing  withsoundnamed:(nsstring *)soundnamed  { self = [super init]; if(self) {     cgsize size = [[ccdirector shareddirector] winsize];     nsstring* plistpath = [[nsbundle mainbundle] pathforresource:@"audiotimings" oftype:@"plist"];      nsdictionary* mydictionary = [nsdictionary dictionarywithcontentsoffile:plistpath];      //needs create array has timing information array plist     //nsstring *text01timing = [mydictionary objectforkey:@"sentance01timing"];     nsstring *text01timing = [mydictionary objectforkey:_sentance01timing];     nsmutablearray * audiointervals = [nsmutablearray arraywithcontentsoffile:text01timing];                                               nslog(@"text01timing %f",audiointervals);       //needs create label , put text in     cgsize maxsize = {800, 200};     cgsize actualsize = [sentance01text sizewithfont:[uifont fontwithname:@"helvetica" size:20]     constrainedtosize:maxsize linebreakmode:uilinebreakmodewordwrap];      cgsize containersize = { actualsize.width, actualsize.height };     cclabelttf *label = [cclabelttf labelwithstring:sentance01text dimensions:containersize                 alignment:uitextalignmentleft fontname:@"helvetica"                                            fontsize:20];      // center label     label.position = ccp( size.width /2 , size.height/6 );     label.color = ccc3(80, 80, 80);     // add label scene     [self addchild:label z:7];   } return self; } @end 

audiotimings.plist

<plist version="1.0"> <dict> <key>timingsen01</key> <array>     <real>0.044444</real>     <real>0.143054</real>     <real>0.213886</real>     <real>0.48055</real>     <real>0.844434</real>     <real>1.345817</real>     <real>1.470816</real>     <real>1.577759</real>     <real>2.020809</real>     <real>2.331917</real> </array> </dict> </plist> 

with many trojanfoe able fix problem main problem initialised objects wernt retained if see better way of things in code please goal learn (but baby steps! pretty new!!) im doing on old mac laptop (so not arc - cant test @ moment) maybe else...

so creating textmangerclass:

@interface textmanagerwithpagenum : cclayer  { //create properties need notice underscore  //nsstring *_varname; nsstring *_background; nsstring* _text;   //mytext nsstring* _soundfile; nsstring* _audiointerval; nsstring* _currpagenumber; } 

declare @property gives access value accessor (getter) , mutator (setter)

 //@property(nonatomic, strong)nsstring* background; - in arc  @property(nonatomic, retain) nsstring* background;  @property(nonatomic, retain) nsstring* text;  @property(nonatomic, retain) nsstring* soundfile;  @property(nonatomic, retain) nsstring* audiointerval;  @property(nonatomic, retain) nsstring* currpagenumber;  

and implementation .m

//@synthesize varname = _varname; @synthesize background = _background; @synthesize text = _text; @synthesize soundfile = _soundfile; @synthesize audiointerval = _audiointerval; @synthesize currpagenumber = _currpagenumber;   -(id)initwithbackground:(nsstring *)background          textfromplist:(nsstring *)text                    soundnamed:(nsstring *)soundfile       audiointervalplist:(nsstring *)audiointerval         currentpage:(nsstring *)currpagenumber   {   self = [super init];   if(self)   {     //_varname = varname;     _text = text;     _audiointerval = audiointerval;     _soundfile = soundfile;     _currpagenumber = currpagenumber;         /*here having problem - important manually retain       , dealloc or wont able use objects created!*/        //audio interval   _audiointerval= [[mydictionary objectforkey:audiointerval]retain];//***please retain me! , dont forget dealloc! :)   nslog(@"audio intervals %@",audiointerval); 

hello world

  textmanagerwithpagenum *mypage =    [[textmanagerwithpagenum alloc]initwithbackground:@"page01bg.png"textfromplist:@"page01text"soundnamed:@"page01" audiointervalplist:@"audiotimings" currentpage:5];                                                 [self addchild:mypage]; 

//hope practicle example of stuffed helps else since more fun learn elses mistakes :p


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -