Archive for the ‘dev’ Category

Tekstbehandlig på #iPhone og #iPad. Oversikt. Oppdatert igjen.

∑ – Den beste tekstbehandleren er den du alltid har på deg

Våre mobile verktøy begynnner litt etter litt å ta over PCen. Det at de er tilgjengelig overalt, gjør at vi går fra å gjøre notater, til å skrive blogg-poster og kanskje til og med hele artikler på iPhone og iPad.
Og enda viktigere, Apples iCloud har gjort vi superenkelt kan jobbe på samme tekst på flere enheter samtidig.
Denne serien av poster om tekstbehandling startet med en enkel post om hvor fornøyd jeg var med mine nye tekstbehandlingapper. Denne var populær, og da var veien kort for meg til å lage en litt bredere serie av poster rundt tekstbehandling.
Tekstbehandling på iPhone og iPad:

  1. Nødvendige egenskaper
  2. Formatter i #HTML
  3. Lynkurs i MarkDown formatteringssrpåk
  4. ByWord – en ny og spennende #MarkDown app
  5. Skjulte muligheter i tastaturet.
  6. Innsetting av bilder med MarkDown
  7. Den beste tekstbehandleren er den du alltid har på deg!

Hvordan filtrere og summere i #CoreData? #iphone #ios

Jeg har skaffet meg et fantastisk verktøy for å gjøre databaseprogrammering på iPhone som heter Sensible Table View (STV) og er fra Sensible Cocoa.

Men da jeg skulle igang med litt mer avanserte filter og tilhørende summeringer, ble jeg sittende fast, ikke et par timer, men en hel uke. Dokumentasjonen av Apples Core Data synes jeg er svært akademisk, og de fem bøkene jeg har om dette er dårlige.

Hintene som hjalp meg fant jeg på Stack Overflow etter å ha søkt etter @sum in core data på Google.

Sammen med Apples dokumentasjon klarte jeg tilslutt å løse problemet innenfor rammene av det nye verktøyet. Etter en ukes slit, ser løsningen latterlig enkel ut. Her er den:

  • Predicate: bare bruk løsningen i STV! Pass bare på å lage predikatet slik:

    filterPredicate:[NSPredicate predicateWithFormat:@“account like ‘kreditt’”]];

  • summering er så uskyldig som dette:

    NSNumber *balance = [transactionSection.items valueForKeyPath: @“@sum.amount”];

    self.title = balance.stringValue;

Dette er vidunderlig! Jeg kan bruke predikater i STV til å lage små og pene datasets, og beregne summen på datasettet i ettertid. Plutselig er det igjen morsomt å være database-programmerer!

Having fun programming old iPhone default binding while waiting for the new – @sensiblecocoa

While we a looking forward to the release on Wednesday, I thought programming old Apple stuff could shorten the time…

User default binding, is a way that your iPhone app can store a list of values in it’s storage, and use the list when restarting the program.

Sensible Table View 3.0 new introduction book, has a nice example at page 35. The example is unbelievable short, and just tell you to do a setup as in Section 3, and writing less than thirty lines.

The example use a SCUserDefaultsDefinition and the normal SCPropertyDefinition, and make the whole magically appear with:

[self.tableViewModel generateSectionsForUserDefaultsDefinition: userDefaultsDef];

The hard task was in fact not to do the initial setup correct…

Hands-on with database framework @sensiblecocoa. #STV30 finally documented – still a bit of black magic to me…

I dropped using my lovely Mac SE30 in the early nineties because of lack of good databases, and moved back to Windows until 2010. SQLite and Core Data seemed powerful enough to serve my need of prototyping and building enterprise application. Alas – they weren’t.

Being fostered on Paradox databases first, and later MS SQL Server, Core Data on iOS is a hell of complications.

Enter Sensible Table View (STV) Framework

Last year however, a cool framework from Sensible Cocoa (at $100) came to my knowledge and I bought it.

Sadly, the framework, created by Tarek Sakr, lacked documentation, at least at my level. I tried, but had to drop it.

I then had a round with Filemaker Pro, witch provide a nice way to prototype database application. I didn’t however, see any way to make sellable apps in the App Store, and in late spring, when my test-version expired, I dropped it also.

STV 3.0 – finally a decent version

Then Sensible Cocoa began promoting an upcoming new version with documentation, and I had something to wait for. When it arrived, I had to shell out another  $125 (I hate being billed for developer stuff!), but no documentation appeared. Finally in version 3.08 it appeared and I could start using it. Vacation approached however, and now I’m in it.

I thought I’d just follow the book, and write every code character. By the way, copying isn’t without danger either…

Copying code from PDF sometimes includes strange invisible characters that destroys the project. You get a lot of not-resolvable and not-visible errors. The solution is to first copy the text to a text-editor like Byword, then copy it again, and finally paste it to XCode.

Back to school

The two-first sections was well known to me, and I started again with Section 3, Setting up STV. Tarek explains well but asks us to name the view-controller RootViewController, which he later calls iPhoneViewController, before he settles down on iPhoneRootViewController for the main part of his book.

A silly detail, but for SQL server people like me, it drove me nut. In the learning phase, inconsistencies just slows us down. I hope Tarek correct these annoyances….

In Section 4 begins the fun — Exploring the possibilities. Tarek let us create a decent task app, and he starts us with a simple task object. He guides you through his structure:

  • Setting up the screen
  • Create the objects definition
  • Create property definitions
  • Create an instance of the objects
  • Create the section(s) for the task object
It’s fun and it’s a bit magical!

Tarek describes his ingenious STV30 architecture like this:

An SCTableViewModel defines a table view model with several sections, each section being of type

SCTableViewSection. Each SCTableViewSection can contain several cells, each cell being of type

SCTableViewCell. SCTableViewModel’s functionality can also be extended using

SCTableViewModelDataSource and SCTableViewModelDelegate.

Progression is smooth and well

Tarek leads you from the single Task object, to a list of objects, adding TaskStep object, and gradually opening for more advanced controls like switch and date-pickers.

I’m now finished with the objects and heading for the real stuff – Core Data. I’ll update the post when I’m further down in Tarek’s PDF…

Preliminary conclusion

For me STV is still a of bit black magic, and I’m not sure if I dare to release a commercial app on that. But for prototyping I’m all in. I agree with Tarek -

STV3.0 is exciting indeed!

Tutorial on programming ERP for iPhone with the new @sensiblecocoa database framework 3.0

The new unfinished user guide, provided as a PDF, is a good place to start. I followed Section 3 to set up the project.

I did made some errors; for instance I didn’t choose the Universal option when creating the project. And worse, I copied some invisible strange characters from the PDF into the source, and it ruined all.

But after a couple of days, and an hour a day, an empty project according to Section 3. was running.

Doing the first tests in Section 4. was also easy. So I decided to jump to Exploring Core Data Binding, which is what really interested me.

I did what the user guide told me, and again got an empty app. The guide didn’t mention to change the AppDelegate files, and after studying these I had a path to follow.

Since the PDF is not half completed, I looked at the samples provided. I got some ideas in the upgraded 2.0 samples, but these samples was written for earlier XCode versions.

What helped me, was the new ParseCom App. It was written in a new XCode version. So I used it’s AppDelegate files to rewrite my own project. And after some bug-fixing, it finally ran. And ran very nice indeed!

I make a receipt for you want to try it out here:

  1. Setup your project as explained in Section 3. in the PDF provided
  2. Do as told in the Section 4. “Exploring Core Data Binding”. Remember to check for Core Data.
  3. Change the AppDelegate.h to the following:

#import <UIKit/UIKit.h>

//Added line
@class ViewController;

@interface AppDelegate : UIResponder`

@property (strong, nonatomic) UIWindow *window;

//Added line
@property (strong, nonatomic) ViewController *viewController;

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;

@end>

  1. And the top of the AppDelegate.m as follows:

#import "AppDelegate.h"
#import "ViewController.h"
#import "iPadDetailViewController.h"

@implementation AppDelegate

@synthesize window = _window;

@synthesize viewController = _viewController;

@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithStyle:UITableViewStyleGrouped];
UIViewController *rootViewController;
rootViewController = [[UINavigationController alloc]initWithRootViewController:self.viewController];`

self.window.rootViewController = rootViewController;

[self.window makeKeyAndVisible];
return YES;
}

Run it on the iPhone simulator and you should have a great template to do ERP database programming on our lovely Apple mobile devices!

Creating a #iPhone #CoreData app the visual way – notes

iPhone iOS 5 programming essentials ch. 39 are using a code first approach. That means defining outlets and actions in code, create the screen objects, and connect them manually.

I however, strongly prefer the UI first way explained by Paul Hegarty in his last Stanford course on iOS programming in the lectures 13 and 14.

Here it is his recommendations:

  • Start with drawing the interface
  • Create a new view controller, clean it, and connect it to the scene
  • Generate code by dragging from the design to the .h file
  • Import Paul’s core data controller from the course

Add the following to the view controller:

  • setupFetchedResultController – setup table and field
  • fetchDataIntoDocument – create initial data
  • useData – if empty call fetchDataIntoDocument, if it does not exists call setupFRC
  • setDatabase – call useData
  • viewWillAppear – setup database from Document

Modify this method:

  • cellForRowAtIndexPath – create each individual cell