Singleton Classes that I don’t abdicate

Paulo Silva : May 20, 2018 15:37 : Development

Since I start developing for iOS, I have some singleton classes that I don’t abdicate in all my projects, because they are very useful and helpful.

The first one is the AppEnvironment, where I have some properties that help-me to perform some checks for the App.

The second one is the UserSettings, that is responsible for manage the App user settings.

Now that I have migrate the classes to swift, I have decide to share them.

Just one little advice, don’t abuse of Singleton classes, because they will compromise the application performance.

And some structs that I dont abdicate also

The first is the AppTheme, where I define all the necessary stuff for the user interface.

The second is the AppSettings, where I define all necessary constants for localization formatting and API configuration also.

Source code on GitHub

Comments are closed

Cappuccino Javascript Framework – Part 2

Paulo Silva : June 18, 2012 17:41 : Development

Consuming .NET JSON WebService – Part 2

The Cappuccino Code

On this post I’ll show you HOW-TO develop and consuming JSON Web Services using the Cappuccino Javascript Framework and .Net 2.0 Framework.

On this step let’s build the Cappuccino RIA Application that will consume the .Net Web Service.

Notes: About the “.d”.

Ok, let’s start writing the Cappuccino code:

//  AppController.h
//  Created by «FULLUSERNAME» on «DATE».
//  Copyright «ORGANIZATIONNAME» «YEAR». All rights reserved.

@import <Foundation/CPObject.j>
@import <AppKit/CPCib.j>

@import <Foundation/CPURLRequest.j>
@import <Foundation/CPJSONPConnection.j>

@import <AppKit/CPToolbar.j>
@import <AppKit/CPToolbarItem.j>
@import <AppKit/CPCollectionView.j>

@implementation AppController : CPObject
	// Main Window
    CPWindow			theWindow;

	 * URLConnection - Used to consume WebServices 
    CPURLConnection		urlConnection;

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
        contentView = [theWindow contentView];

    var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];

    [label setStringValue:@"Hello World!"];
    [label setFont:[CPFont boldSystemFontOfSize:24.0]];

    [label sizeToFit];

    [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
    [label setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds]) - CGRectGetWidth([label frame])) / 2.0, (CGRectGetHeight([contentView bounds]) - CGRectGetHeight([label frame])) / 2.0)];

    [contentView addSubview:label];

    [theWindow orderFront:self];

    /// Uncomment the following line to turn on the standard menu bar.
    //[CPMenu setMenuBarVisible:YES];
	 * Using the CPURLConnection to consume JSON .NET WebServices
    var request = [CPURLRequest requestWithURL:"http://localhost:8081/Services/XmlJson.asmx/ListJSON"];
	[request setHTTPMethod: "POST"]; 
    [request setValue:"application/json; charset=utf-8" forHTTPHeaderField:"Content-Type"]; 
	urlConnection = [CPURLConnection connectionWithRequest:request delegate:self];


 * CPURLConnection Delegate Methods

 * this method is the responsavel to treat the received data, is on this method that you have to manipulate your data.
- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data
	/// Convert the recived JSON data to Cappuccino Object
	var _data = CPJSObjectCreateWithJSON(data);

	/// the ".d" in .Net 2.0 or 3.5 JSON WebServices is implemented because of security measures.
	_data = eval(_data.d);
	alert("data = " + _data);
	alert("_data[0].firstName = " + _data[0].firstName);


 * If you have any type of error during the connection process, this is the method responsible to notify you about the error.
- (void)connection:(CPURLConnection)aConnection didFailWithError:(CPError)error
    [self connectionDidFinishLoading:aConnection];

 * this is the method responsavel to tell you that the process of receiving data was ended, 
 * and here you can release all unnecessary variables.
- (void)connectionDidFinishLoading:(CPURLConnection)aConnection
    if (aConnection == urlConnection)
        urlConnection = nil;


Download the source code, with Cappuccino Framework.

Consuming .Net Web Services with Cappuccino.


Cappuccino Javascript Framework – Part 1

Paulo Silva : June 1, 2012 18:26 : Development

Consuming .NET JSON WebService – Part 1

The .NET WebService

On this post I’ll show you HOW-TO develop and consuming JSON Web Services using the Cappuccino Javascript Framework and .Net 2.0 / 3.5 Framework.

In first step, let’s build the JSON .Net WebService, using Microsoft or Mono Framework. To simplify this post I’ll not use the code behind.

As we know, to use JSON on .NET WebServices we need to use the following assembly “Microsoft.Web.Extensions.dll”, and in the code we need to define the following namespaces: System.Web.Script.Services, System.Web.Script.Serialization.

Ok, let’s start writing the .Net JSON WebService (XmlJson.asmx) code:

<%@ WebService Language="C#" Class="Services.XmlJson" %>
using System;
using System.Globalization;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

// Script namespace from Microsoft.Web.Extensions.dll assembly
using System.Web.Script.Services;
using System.Web.Script.Serialization;

namespace Services

    /// <summary>
    /// Summary description for WebService
    /// </summary>
    [WebService(Namespace = "")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    // To allow this Web Service to be called from script, using ASP.NET AJAX. 
    public class XmlJson : System.Web.Services.WebService

        private Contact _Contact;

        public XmlJson() { }

        public string About()
            return "Version 1.0";

        // ResponseFormat is JSON
        public string ListJSON()
            ArrayList list = new ArrayList();
            _Contact = new Contact("First Name 1", "Last Name 1");

            _Contact = new Contact("First Name 2", "Last Name 2");

            Contact[] resultList = (Contact[]) list.ToArray(typeof(Contact));

            // JSON Response
            JavaScriptSerializer jss = new JavaScriptSerializer();
            string serializedObj = jss.Serialize(resultList);

            return serializedObj;

    /// our serializable contact class
    public class Contact
        private string _firstName;
        private string _lastName;

        public Contact() {}

        public Contact(string firstName, string lastName){
            this._firstName = firstName;
            this._lastName = lastName;

        public string firstName
            get { return this._firstName;}
            set { this._firstName = value;}

        public string lastName
            get { return this._lastName;}
            set { this._lastName = value;}

Download the .Net source code.

Running ASPX Web Services on Mac OS X using Mono.

Create a Mono Develop Solution for the source code.

Leave a response »
« Page 1 »

One Reply to “Development”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.