1

i have this code in bezier.m

for(int x = 0; x < [globalArray count]; ++x){
    NSInteger numOfCurves = [globalArray[x] count];
    UIBezierPath *linesegment = [UIBezierPath bezierPath];
    for(int y=0; y< numOfCurves; y++){
        [UIBezierPath makeControlPoints:globalArray[x]];
        [UIBezierPath makeAnchorPoints:globalArray[x]];
        linesegment = [UIBezierPath makeTheCurve:globalArray[x]];
    }       

    strPaths = [NSString stringWithFormat:@"%@", linesegment];
    NSLog(@"log %@", strPaths);

    linesegment.lineWidth = [[self.linesWidth objectAtIndex:x] floatValue];
    [[UIColor blackColor] setStroke];
    linesegment.lineCapStyle = kCGLineCapRound;
    [linesegment stroke];
}

I need to get the value of "strPaths" past to viewcontroller.m which is the output is below

  log <UIBezierPath: 0x7fd50147ff30; <MoveTo {201, 130.5}>,
   <CurveTo {167.25000023841858, 130.6666666418314} {188.66666698455811,      130.33333332836628} {176.33333396911621, 130.16666665673256}>,
  <CurveTo {145.83333325386047, 134.75} {158.16666650772095,      131.16666662693024} {152.33333301544189, 132.33333325386047}>,
  <CurveTo {129.25000017881393, 146} {139.33333349227905, 137.16666674613953} 

    log <UIBezierPath: 0x7fd50147ff30; <MoveTo {201, 130.5}>,
       <CurveTo {167.25000023841858, 130.6666666418314} {188.66666698455811,            130.33333332836628} {176.33333396911621, 130.16666665673256}>,
       <CurveTo {145.83333325386047, 134.75} {158.16666650772095,      131.16666662693024} {152.33333301544189, 132.33333325386047}>,
       <CurveTo {129.25000017881393, 146} {139.33333349227905, 137.16666674613953}

and so on....

BoMB
  • 5
  • 5
  • 2
    possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Hot Licks Aug 11 '15 at 02:42

4 Answers4

1

You could use NSUserDefaults for storing value as below

[[NSUserDefaults standardUserDefaults]setValue:strPaths forKey:@"strPaths"];

and retrieve that data as given below

[[NSUserDefaults standardUserDefaults] valueForKey:@"strPaths"];

Hope this helps..

Balaji Ramakrishnan
  • 1,909
  • 11
  • 22
  • i have to this drawing lines value everytime I move touch it showing the control points. I need to gather all of that. edited my sample output. – BoMB Aug 10 '15 at 07:27
1

There are better ways than NSUserDefaults. You can use delegation and pass those values from 'bazier.m' to 'viewcontroller.m'. Or use NSNotificationCenter with custom notification.

sloik
  • 694
  • 5
  • 12
1

Your first priority should be to write a block for this, and return the value through the block every time in the loop. (If you are calling a conceptually static function)

If not, your next priority should be to create a delegate for this class and pass the value back in the delegate method.

If that is also not possible, you should opt for NSNotificationCenter and post notifications to an observer.

danialzahid94
  • 4,103
  • 2
  • 19
  • 31
0

I solved it by adding -> [strSuccess appendString:strCoor];

NSMutableString *strSuccess = [[NSMutableString alloc]init];
for(int x = 0; x < [globalArray count]; ++x){
    NSInteger numOfCurves = [globalArray[x] count];
    UIBezierPath *linesegment = [UIBezierPath bezierPath];
    for(int y=0; y< numOfCurves; y++){
        [UIBezierPath makeControlPoints:globalArray[x]];
        [UIBezierPath makeAnchorPoints:globalArray[x]];
        linesegment = [UIBezierPath makeTheCurve:globalArray[x]];
        strCoor = [NSString stringWithFormat:@"%@", linesegment];
    }
    [strSuccess appendString:strCoor];
    strPaths = [NSString stringWithFormat:@"======%@", strSuccess];

    linesegment.lineWidth = [[self.linesWidth objectAtIndex:x] floatValue];
    [[UIColor blackColor] setStroke];
    linesegment.lineCapStyle = kCGLineCapRound;
    [linesegment stroke];
}

thank you guys for the help.

BoMB
  • 5
  • 5