Archive for the ‘programming’ Category

Is the new @SensibleCocoa easier for ERP programming on iOS?

Last year I had high hopes for Sensible Cocoas Sensible Table View framework for iOS. But I couldn’t make the framework working as I wanted. And when Stanford came with its course, I shifted track.

The lasts months, changes had been promised to the framework in the 3.0 version. I’ve been following it, and when they reached 3.06 version with a complete documentation, I decided to update.

I also have to mention, that the investor presentation in Deloitte, Oslo and an hour long interview which Horace Dediu, did clarify both the what, how and why parts of my Global Accounting project. These clarified thoughts, together with what I saw at the SensibleCocoa website, somehow clicked together.

Starting programming Objective-C was far easier now. I’ve certainly learned a lot the last year, which made me pass a handful of hurdles in getting a Sensible Cocoa project up and running myself.

I get the sense however, that the normal SensibleCocoa customer is way more advanced than myself.

But the rest of us also need to do database programming in iOS, so I’ll write a short tutorial in the next post. Then you could self decide if the framework are easier to work with for us laymen.

6 posts on #iPhone & #iPad Enterprise Resource Programming: Database and PDF-reporting are covered

Erp
Creating enterprise apps for iPhone and iPad isn’t trivial. In @iFacturas we used 21 months to get out the current version. Now I’m diving into enterprise programming myself, in order to find a better way to do it. 
If you know me, you also know I’m loving accounting, specially accounting program design. In many years, there has been two important parts of accounting programs, entering data and reports.
Entering data has to do with database and database view programming. Reports with the same database and presenting reports, normally on PDF.
I’ve just finished a roundtrip on database and PDF programming, and have documented the process and the source here in 6 blogposts:
I may have found the golden egg in #iOS database programming! It’s @sensiblecocoa
I’ve earlier told you about that programming iPhone isn’t that hard. That was only partly true however. For database programming in iPhon…
Update: Hands-on with @sensibleCocoa #iOS tableView framework – I see light in the tunnel!
I’ve got the “Sensible Tableview” installed. I’ve passed the videos one more time, and now I’m hands-on. Yesterday I tried a small project …
#iOS PDF programming isn’t that difficult either. The hard part is to know where to start ;)
I like to create a PDF file in my iPhone app. I then did spent to much time looking at various PDF framework. I didn’t want to reinvent a…
…  Apple’s print tutorial for iOS does a good job explaining it. But sadly, the tutorial has a bug in this call. 
When preparing for the following, and hopefully last, post, I decided to try to store the project in github.com to let you easily share it. That drove my tutorial to an halt. Without really knowing anything, I did a git init and git commit command, and suddenly all my source-files disappeared!
I’ve combined the iPhone 4 Development Essesials for XCode  Chapters 32 and 33, with  Apple’s print tutorial for iOS. Most of it is wrapped into the following savePdfFile method:
Good luck with the posts! If you like I may record videos on the post. It depends on the comments…

My #iOS PDF programming posts are coming to and end. This last tells you how to to finish it.

Pdf-logo

I've combined the iPhone 4 Development Essesials for XCode  Chapters 32 and 33, with  Apple's print tutorial for iOS. Most of it is wrapped into the following savePdfFile method:


– (IBAction)savePDFFile:(id)sender

{

    NSString* path = [[NSBundle mainBundle] pathForResource:@”sampleData” ofType:@”plist”];

    

    // get a temprorary filename for this PDF

    path = NSTemporaryDirectory();

    self.pdfFilePath = [path stringByAppendingPathComponent:

                        [NSString stringWithFormat:@"%d.pdf"

                         [[NSDate date

                          timeIntervalSince1970] ]];

    

    // Prepare the text using a Core Text Framesetter

    CFAttributedStringRef currentText = CFAttributedStringCreate(NULL

                                                                 (CFStringRef)textView.text, NULL);

    if (currentText) {

        CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);

        if (framesetter) {

            

            NSString* pdfFileName = self.pdfFilePath; //[NSString stringWithString:@"test.pdf"];

            

            // Create the PDF context using the default page: currently constants at the size 

            // of 612 x 792.

            UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);

            

            CFRange currentRange = CFRangeMake(0, 0);

            NSInteger currentPage = 0;

            BOOL done = NO;

            

            do {

                // Mark the beginning of a new page.

                UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth

                                                          kDefaultPageHeight), nil);

                

                // Draw a page number at the bottom of each page

                currentPage++;

                [self drawPageNumber:currentPage];

                

                // Render the current page and update the current range to

                // point to the beginning of the next page.

                currentRange = [self renderPage:currentPage withTextRange:

                                currentRange andFramesetter:framesetter];

                

                // If we're at the end of the text, exit the loop.

                if (currentRange.location == CFAttributedStringGetLength

                    ((CFAttributedStringRef)currentText))

                    done = YES;

            } while (!done);

            

            // Close the PDF context and write the contents out.

            UIGraphicsEndPDFContext();

            

            // Release the framewetter.

            CFRelease(framesetter);

            

        } else {

            NSLog(@”Could not create the framesetter needed to lay out the atrributed string.”);

        }

        // Release the attributed string.

        CFRelease(currentText);

    } else   NSLog(@”Could not create the attributed string for the framesetter”);

}

The whole source is available at https://github.com/mortjac/PDF-tutorial. So now you can contribute and make the project better. Thank you for patiently reading my posts!

       

#iOS programming is too hard to risk the code. A sidestep on using #git and @github to control it.

Pdf-logo

When preparing for the following, and hopefully last, post, I decided to try to store the project in github.com to let you easily share it. That drove my tutorial to an halt. Without really knowing anything, I did a git init and git commit command, and suddenly all my source-files disappeared!

I ceratinly had done something wrong, and had to try to learn Git in order to finish my small tutorial. At least I had to use Time Machine to restore the files, and recreate the project using Apple's built-in Git support.

During the work I had a lot of help from the website to the book “Pro Git” by Scott Chaconn. He almost succeded in make me understand it. Way better than the “Git for dummies” wikis, which are made for much more advanced pupils than myself.

I had to redo my project, marking it for the use of Git. Then I followed the steps in on github help. So now you can get the the PDF-tutorial files at https://github.com/mortjac/PDF-tutorial.

In order to get the files into you XCode 4 follow these steps from Spitzkoff:

  1. Go to Organiser -> Repositories -> + -> Add repository… -> Type in your GitHub's repository name -> Paste either SSH path or https, both work.
  2. Click Clone
  3. Show xCode where to Download existing repository
  4. Start working on the project, commit as above.

Boy, this was pretty hard to get this post out! Please correct me on github if I could do it better or if I have sneaked a bug into it! 

#iOS PDF programming is still not that difficult. Now we dive into #PDF itself ;)

In the last post I described how to “draw” on iOS, which served me well in getting me started on iOS PDF programming.

Now I will combine Apple’s print tutorial for iOS and what I’ve learned about drawing:

As with “drawing”, writing PDF isn’t that complicated if you sit down and decipher it. And  Apple’s print tutorial for iOS does a good job explaining it. But sadly, the tutorial has a bug in this call. The tutorial wrongly writes:
currentRange = [self renderPageWithTextRange:currentRange andFramesetter:framesetter];

instead of the correct:

currentRange = [self renderPage:currentPage withTextRange:currentRange andFramesetter:framesetter];
So I got this part running pretty well with the following code:
- (IBAction)savePDFFile:(id)sender

{
    NSString* path = [[NSBundle mainBundle] pathForResource:@”sampleData” ofType:@”plist”];
    
    // get a temprorary filename for this PDF
    path = NSTemporaryDirectory();
    self.pdfFilePath = [path stringByAppendingPathComponent:
                        [NSString stringWithFormat:@"%d.pdf"
                        [[NSDate date
                        timeIntervalSince1970] ]];
    
   // Prepare the text using a Core Text Framesetter
    CFAttributedStringRef currentText = CFAttributedStringCreate(NULL
                                (CFStringRef)textView.text, NULL);
    if (currentText) {
        CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
        if (framesetter) {
            
            NSString* pdfFileName = self.pdfFilePath; //[NSString stringWithString:@"test.pdf"];
            
            // Create the PDF context using the default page: currently constants at the size 
            // of 612 x 792.
            UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);
            
            CFRange currentRange = CFRangeMake(0, 0);
            NSInteger currentPage = 0;
            BOOL done = NO;
            
            do {
                // Mark the beginning of a new page.
                UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth
                                                          kDefaultPageHeight), nil);
                
                // Draw a page number at the bottom of each page
                currentPage++;
                [self drawPageNumber:currentPage];
                
                // Render the current page and update the current range to
                // point to the beginning of the next page.
                currentRange = [self renderPage:currentPage withTextRange:
                                currentRange andFramesetter:framesetter];
                
                // If we’re at the end of the text, exit the loop.
                if (currentRange.location == CFAttributedStringGetLength
                    ((CFAttributedStringRef)currentText))
                    done = YES;
            } while (!done);
            
            // Close the PDF context and write the contents out.
            UIGraphicsEndPDFContext();
            
            // Release the framewetter.
            CFRelease(framesetter);
            
        } else {
            NSLog(@”Could not create the framesetter needed to lay out the atrributed string.”);
        }
        // Release the attributed string.
        CFRelease(currentText);
    } else {
        NSLog(@”Could not create the attributed string for the framesetter”);
    }    
}
The problem was that I couldn’t verify if the PDF was written to the iPhone or not. In the next post I will describe how I combined it with code from Spitzkoff.

#iOS PDF programming isn’t that difficult either. The hard part is to know where to start ;)

Pdf-logo

I like to create a PDF file in my iPhone app. I then did spent to much time looking at various PDF framework. I didn't want to reinvent anything, but the frameworks I looked at just made things more complicated. So today I started to do it the Apple way, that's using Quartz 2D framework in iOS SDK.

Happily I already have iPhone 4 Development Essesials for XCode 4 in my Kindle, so I started on Chapters 32 and 33, which gives an introduction and lesson in Quarts 2D programming. I started with drawing lines, rectangles and ended up with ellipses. And the code drawing the image wasn't difficult at all:

– (void)drawRect:(CGRect)rect
{
    // Setting context
    CGContextRef context = UIGraphicsGetCurrentContext();
    // Setting line width
    CGContextSetLineWidth(context, 2.0);
    // Setting color
    CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
    // Create a rectangle
    CGRect rectangle = CGRectMake(60,170,200,80);
    // Create an ellipse inside
    CGContextAddEllipseInRect(context, rectangle);
    // Draw
    CGContextStrokePath(context);
}

Somehow, I can use Quartz 2D to draw text too. That's the task in the next post where I will combine Apple's tutorial and what I've learned about PDF in iOS from Spitzkoff.