Skip to content

moky/snowcat-ios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SnowCat

SnowCat.framework for iOS application is a framework for developing apps via creating some '.plist' files simply.

It is based on SlanissueToolkit.framework, copyright ©2015 Slanissue.com.

Snowcat


Example 1: "Hello world"

Downloads :

Classes/AppDelegate.m

#import "SnowCat.h"

...

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	CGRect frame = [[UIScreen mainScreen] bounds];
	self.window = [[[UIWindow alloc] initWithFrame:frame] autorelease];
	// Override point for customization after application launch.
	
	NSString * entrance = @"main.plist";
	entrance = [SCApplicationDirectory() stringByAppendingPathComponent:entrance];
	[SCWindow launch:entrance withWindow:self.window];
	
	self.window.backgroundColor = [UIColor whiteColor];
	[self.window makeKeyAndVisible];
	return YES;
}

Resources/main.plist

Root : {
	version : "1.0",
	Node : {
		comment : "Here is the main entrance",
		window : {
			/* defined 'page1' in another 'Node' file */
			rootViewController : 'include file="page1.plist" replace="name: girl"'
		}
	}
}

Resources/page1.plist

Root : {
	Node : {
		Class   : "ViewController",
		comment : "This is page 1",
		view    : {
			subviews : [
				{ /* view 1 */
					Class  : "Label",
					text   : "Hello world!",
					color  : "{0, 0, 255}",
					center : "{center, middle - 100}"
				},
				/* view 2, defined in another 'Node' file, in order to reuse */
				'include file="btn1.plist" attributes="center: {center, middle}"',
				{ /* view 3 */
					Class  : "ImageView",
					image  : "Icon.png",
					size   : "{100, 100}"
					center : "{center, middle + 100}",
					events : {
						"msg.page1.button1.clicked" : [
							{ /* action 1 */
								name    : "ToggleVisibility",
								target  : "self"
							}
							/* more actions, see 'snowcat-ios/uikit/actions/' */
						]
					},
					notifications : [
						/* all these notifications will be transfered to events */
						"msg.page1.button1.clicked"
					]
				}
			] /* EOF 'subviews' */
		} /* EOF 'view' */
	}
}

Resources/btn1.plist

Root: {
	Node : {
		Class   : "Button",
		comment : "This is button 1",
		title   : "click me",
		color   : "{255, 0, 0}",
		events  : {
			onClick : [
				{ /* action 1 */
					name    : "Alert",
					title   : "Hey ${name}",
					message : "Should I date you?",
					ok      : "Of course!"
				},
				{ /* action 2 */
					name    : "Notification",
					event   : "msg.page1.button1.clicked"
				}										
			]
		}
	}
}

Example 2: "Notifications & Callback"

I suggest you controlling the UI via notifications, but not codes, the best habit is NOT writing any UI codes in your controllers.

You can do some calculating works in your codes (e.g.: a singleton instance), and send out a notification to notice all guys that interest in the results. As all SnowCat views & controllers can define a 'notifications' list and do some actions when these 'events' happen, we can let the framework to do the UI works.

Meanwhile, you should send out a notification when some events happen in UI level (e.g.: a button clicked), so that guys interest in it will do their works when received this notification.

There are two ways to callback from the UI level:

  1. Notification
  2. CallFunc

Classes/controller/MyController.h

#import "SnowCat.h"

#define MSG_BUTTON1_CLICKED @"msg.page1.button1.clicked"
#define MSG_XXX             @"msg.whatever"

@interface MyController : SCViewController

@end

Classes/controller/MyController.m

#import "MyController.h"

@implementation MyController

- (void) dealloc
{
	NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
	[center removeObserver:self
	                  name:MSG_BUTTON1_CLICKED
	                object:nil];
	
	[super dealloc];
}

/* the designated initializer */
- (instancetype) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
	self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
	if (self) {
		NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
		[center addObserver:self
		           selector:@selector(_button1Notification:)
			           name:MSG_BUTTON1_CLICKED
			         object:nil];
	}
	return self;
}

- (void) _button1Notification:(NSNotification *)notification
{
	// TODO: handle button1 clicked notification here.
	
	// the 'userInfo' is a dictionary of the action's definition,
	// you can get all data you need here
	NSDictionary * aDict = [notification userInfo];
	SCLog(@"user info: %@", aDict);
	
	NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
	[center postNotificationName:MSG_XXX object:nil userInfo:aDict];
}

@end

Classes/view/MyButton.h

#import "SnowCat.h"

@interface MyButton : SCButton

@end

Classes/view/MyButton.m

#import "MyButton.h"

@implementation MyButton

- (BOOL) setAttributes:(NSDictionary *)dict
{
	if (![super setAttributes:dict]) {
		SCLog(@"definition error: %@", dict);
		return NO;
	}
	// TODO: set extra attributes for your button here
	// the parameters 'dict' is the dictionary defined in plist
	
	// NOTICE: this function will be called after added to superview.
	return YES;
}

- (void) onClick:(id)sender
{
	[super onClick:sender];
	
	// TODO: handle 'onClick:' event here
	
	// sender is the self button
	SCLog(@"sender: %@", sender);
}

- (void) _click:(NSObject *)object
{
	// TODO: handle 'CallFunc' action here
	
	// you can also call a function without parameter, or two parameters
	NSString * str = (NSString *)object;
	SCLog(@"object: %@", str);
}

@end

Resources/theme1.bundle/page1/btn1.plist

Root: {
	Node : {
		Class  : "Button",
		title  : "click button 1",
		color  : "{255, 0, 0}",
		events : {
			onClick : [
				{
					name     : "Notification",
					event    : "msg.page1.button1.clicked"
				}
			],
			"msg.whatever" : [
				{
					name     : "View",
					target   : "parent",
					selector : "addSubview:",
					view     : 'include file="btn2.plist" attributes="center: {200, 100}"'
				},
				{
					name     : "Hide",
					target   : "self"
				}
			]
		},
		notifications : [
			"msg.whatever"
		]
	}
}

Resources/theme1.bundle/page1/btn2.plist

Root: {
	Node : {
		Class  : "MyButton",
		title  : "click button 2",
		color  : "{0, 255, 0}",
		events : {
			onClick : [
				{
					name     : "CallFunc",
					selector : "_click:",
					object   : "${name}"
				}
			]
		}
	}
}

Example 3: "Beva apps"

Downloads :

All these Beva apps are based on this framework, but you know, I cannot offer you these source codes, BAZINGA!~ :P

                                -- by moKy @ Sept. 25, 2015 (Mid-Autumn Festival Eve)

About

SnowCat.framework for iOS application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages