Objective oriented programming
Objective-C 2.0 Programming language A guideline by Apple Developers Message syntax
Person *voter; //assume this exists [voter castBallot]; int theAge = [voter age]; [voter setAge:21]; if ([voter canLegallyVote]) { // do something voter-y } [voter registerForState:@"CA" party:@"Independant"]; NSString *name = [[voter spouse] name];
Types
Class introspection//inquire an object about its class Class myClass = [myObject class]; NSLog(@"My class is %@", [myObject className]); //testing for general class membership (subclasses included): if ([myObject isKindOfClass:[UIControl class]]) { // something } //testing for specific class membership (subclasses excluded): if ([myObject isMemberOfClass:[NSString class]]) { // something string specific } Objects
if (object1 == object2)
if ([object1 isEqual: object2])
Foundation Framework
NSString *aString = @"Hello World!"; if ([aString hasPrefix:@"He"]) { // will make it here }
ClassesClass definition
=== e.g. Header:Person.h === #import <Foundation/Foundation.h> @interface Person : NSObject { // instance variables NSString *name; int age; } // method declarations - (NSString *)name; - (void)setName:(NSString *)value; - (int)age; - (void)setAge:(int)age; - (BOOL)canLegallyVote; - (void)castBallot; @end === e.g. Implementation:Person.c === #import "Person.h" @implementation Person - (BOOL)canLegallyVote { return ([self age] >= 18); } - (void)castBallot { if ([self canLegallyVote]) { // do voting stuff } else { NSLog (@“I’m not allowed to vote!”); } } @end
[super doSomething]; Object
Person *person = nil; person = [[Person alloc] init];
Person *person = [[Person alloc] init]; // Retain count begins at 1 with +alloc [person retain]; // Retain count increases to 2 with -retain [person release]; // Retain count decreases to 1 with -release [person release]; // Retain count decreases to 0, -dealloc automatically called
@property int age; // read-write by default @property (readonly) BOOL canLegallyVote; // Memory management policies (only for object properties) @property (assign) NSString *name; // pointer assignment @property (retain) NSString *name; // retain called @property (copy) NSString *name; // copy called
@implementation Person - (void)doSomething { name = @“Fred”; self.name = @“Fred”; } Controls
Anatomy
Nib files: layout user interface elements, add controller objects, connect controller & UI Controls and target-action - (void)actionMethod; - (void)actionMethod:(id)sender; - (void)actionMethod:(id)sender withEvent:(UIEvent *)event; UIScrollView
CGRect frame = CGRectMake(0, 0, 200, 200); scrollView = [[UIScrollView alloc] initWithFrame:frame];
frame = CGRectMake(0, 0, 500, 500); myImageView = [[UIImageView alloc] initWithFrame:frame]; [scrollView addSubview:myImageView]; scrollView.contentSize = CGSizeMake(500, 500);
scrollView.maximumZoomScale = 2.0; scrollView.minimumZoomScale = scrollView.size.width / myImage.size.width; // Delegate implementation - (UIView *)viewForZoomingInScrollView:(UIView *)view { } return someViewThatWillBeScaled; } // Set zoom scale - (void)setZoomScale:(float)scale animated:(BOOL); - (void)zoomToRect:(CGRect)rect animated:(BOOL);
// Provide number of sections and rows - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; // Provide cells for table view as needed - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation; - (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation; - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation; - (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation; - (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation; - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
// For a navigation hierarchy... - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } // Get the row and the object it represents NSUInteger row = indexPath.row id objectToDisplay = [myObjects objectAtIndex:row]; // Create a new view controller and pass it along MyViewController *myViewController = ...; myViewController.object = objectToDisplay; [self.navigationController pushViewController:myViewController animated:YES]; Almost all academic research is being done on Unix environment; therefore, majority of people in academia stick with Linux despite its ambiguity. Luckily, MacOSX is unix-based operating system which provides ease of use, as well as powerful performance, and compatibility with unix applications. This is simple how to setup a mac for own research and apparently, currently ongoing application development.
The first thing you all probably need is to install xCode. Apple incorporates all prerequisites, including basic programming tools, support for various programming languages, compilers into a single developmental suite xCode. By installing xCode, you will be set to go.
In order to install other unix program in MacOS, one may try typing configure, make, then make install for all programs. However, that's just too much time and labor, since a lot of programs require prerequisites before making installation, and many do not tell you what you need in firsthand. Darwin Ports is a great tool which can figure out what other applications needed to be installed, and grabs source itself, and installs automatically. Darwin ports is a great open source environment for Mac users and itself is an automator. Once you have installed the program (install DarwinPorts), you may install other applications by typing following commands in terminal. Setting up the shell environment (add /opt/local/bin to path) echo 'export PATH=/opt/local/bin:/opt/local/sbin:$PATH' >> ~/.bash_profile echo 'export DISPLAY=:0.0' >> ~/.bash_profile Usage (e.g. installing xfig): sudo port -d selfupdate update to current version sudo port install xfig fetch and install xfig and its prerequisites
Simple bash commandsln -s /some/name # creates link ./name pointing to /some/name ln -s /some/name spud # creates link ./spud pointing to /some/name ln -s a b .. # creates links ../a and ../b pointing to ./a and ./b Reference |
Laboratory >