четвер, 15 вересня 2011 р.

Objective-c або @"Що робити коли дуже хочеться та ніяк не виходить."

Привіт всім! Сьогодні темою розмови, як Ви зрозуміли буде Objective - c. Зразу скажу, що дана стаття написана, не для тих хто є щасливими володарями MacBook, Mac Pro або Mac Mini в крайньому випадку. Тут описано, як на звичайному ПК в домашніх умовах, попрацювати з самою мовою.
Коли я вперше почув про Obj_c. то сказано там було, мовляв це тойже С тільки з надбудовами, але маю сказати, чи то я мало про нього дізнався ще, чи тільки в мене одного склалася така думка, але старшим братом я б не назвав Obj_c -> C.
Так, синтаксис в принципі тойже, але там бувають такі частини коду, з таким шаманством, що починаєш думати, а чи не призвеш ти цим набором слів якогось демона(не плутать з потоками java), вслід за яким вваляться Сем і Дін Вінчестери на своїй імпалі (Supernatural). Але демони то потім, спочатку треба встановити компілятор і всих хто нам буде допомагати в цій нелегкій справі.
Даний приклад приведено для Ubuntu.(http://www.techotopia.com/index.php/Installing_and_Using_GNUstep_and_Objective-C_on_Linux)

0) заходимо в термінал в моєму випадку ctrl+alt+t
1) sudo apt-get install gnustep
2) sudo apt-get install gnustep-devel
3) sudo apt-get install gobjc
4)  . /usr/share/GNUstep/Makefiles/GNUstep.sh
5) Встановлюємо http://www.scintilla.org/SciTE.html sudo apt-get install scite
6) Вкидуємо наступну частину коду:
 


#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        NSLog (@"hello world");
        [pool drain];
        return 0;
}

7) В графі Language вибираємо С/С++. Зберігаємо файл, як hello.m
8) Натискуємо F8 та вписуємо справа отаке заклинання:
gcc `gnustep-config --objc-flags` -lgnustep-base hello.m -o hello
9) Тамже потім пишемо ./hello

Для автозаповнення слів, служить комбінація ctrl+ enter
Для того, щоб трошки полегшить собі життя, я підготував невеличкий словничок, який можна кидати в кінець файлу, після чого слів для автозаповнення стає більше, проте це тимчасовий вихід, буду шукати інші.


/*
(~THE_DICTIONARY_OF_OBJECTIVE_C_WORDS~)
(
@interface @implementation @end @class @property @protocol @selector @synthesize @private @protected @public
void return BOOL YES NO new unsigned const volatile in out inout bycopy byref oneway self
#pragma
char short int long float double signed unsigned id 

 NSAffineTransform NSAppleEventDescriptor NSAppleEventManager NSAppleScript NSArchiver NSArray
 NSAssertionHandler NSAttributedString NSAutoreleasePool NSBlockOperation NSBundle NSCache 
 NSCachedURLResponse NSCalendar NSCharacterSet NSClassDescription NSCloneCommand NSCloseCommand 
 NSCoder NSComparisonPredicate NSCompoundPredicate NSCondition NSConditionLock NSConnection NSCountCommand 
 NSCountedSet NSCreateCommand NSData NSDataDetector NSDate NSDateComponents NSDateFormatter NSDecimalNumber 
 NSDecimalNumberHandler NSDeleteCommand NSDeserializer NSDictionary NSDirectoryEnumerator NSDistantObject 
 NSDistantObjectRequest NSDistributedLock NSDistributedNotificationCenter NSEnumerator NSError NSException 
 NSExistsCommand NSExpression NSFileHandle NSFileManager NSFileWrapper NSFormatter NSGarbageCollector NSGetCommand 
 NSHashTable NSHost NSHTTPCookie NSHTTPCookieStorage NSHTTPURLResponse NSIndexPath NSIndexSet NSIndexSpecifier 
 NSInputStream NSInvocation NSInvocationOperation NSKeyedArchiver NSKeyedUnarchiver NSLinguisticTagger 
 NSLocale NSLock NSLogicalTest NSMachBootstrapServer NSMachPort NSMapTable NSMessagePort NSMessagePortNameServer 
 NSMetadataItem NSMetadataQuery NSMetadataQueryAttributeValueTuple NSMetadataQueryResultGroup NSMethodSignature 
 NSMiddleSpecifier NSMoveCommand NSMutableArray NSMutableAttributedString NSMutableCharacterSet NSMutableData 
 NSMutableDictionary NSMutableIndexSet NSMutableSet NSMutableString NSMutableURLRequest NSNameSpecifier 
 NSNetService NSNetServiceBrowser NSNotification NSNotificationCenter NSNotificationQueue NSNull 
 NSNumber NSNumberFormatter NSObject NSOperation NSOperationQueue NSOrderedSet NSOrthography 
 NSOutputStream NSPipe NSPointerArray NSPointerFunctions NSPort NSPortCoder NSPortMessage NSPortNameServer 
 NSPositionalSpecifier NSPredicate NSProcessInfo NSPropertyListSerialization NSPropertySpecifier NSProtocolChecker NSProxy 
 NSQuitCommand NSRandomSpecifier NSRangeSpecifier NSRecursiveLock NSRegularExpression NSRelativeSpecifier NSRunLoop NSScanner 
 NSScriptClassDescription NSScriptCoercionHandler NSScriptCommand NSScriptCommandDescription NSScriptExecutionContext NSScriptObjectSpecifier 
 NSScriptSuiteRegistry NSScriptWhoseTest NSSerializer NSSet NSSetCommand NSSocketPort NSSocketPortNameServer NSSortDescriptor 
 NSSpecifierTest NSSpellServer NSStream NSString NSTask NSTextCheckingResult NSThread NSTimer NSTimeZone NSUnarchiver NSUndoManager 
 NSUniqueIDSpecifier NSURL NSURLAuthenticationChallenge NSURLCache NSURLConnection NSURLCredential 
 NSURLCredentialStorage NSURLDownload NSURLHandle NSURLProtectionSpace NSURLProtocol NSURLRequest NSURLResponse 
 NSUserDefaults NSValue NSValueTransformer NSWhoseSpecifier NSXMLDocument NSXMLDTD NSXMLDTDNode NSXMLElement 
 NSXMLNode NSXMLParser  NSCoding NSComparisonMethods NSConnectionDelegate NSCopying NSDecimalNumberBehaviors 
 NSErrorRecoveryAttempting NSFastEnumeration NSFileManagerDelegate NSKeyedArchiverDelegate NSKeyedUnarchiverDelegate 
 NSKeyValueCoding NSKeyValueObserving NSLocking NSMachPortDelegate NSMetadataQueryDelegate NSMutableCopying 
 NSNetServiceBrowserDelegate NSNetServiceDelegate NSObjCTypeSerializationCallBack NSObject NSPortDelegate 
 NSScriptingComparisonMethods NSScriptKeyValueCoding NSScriptObjectSpecifiers NSSpellServerDelegate 
 NSStreamDelegate NSURLAuthenticationChallengeSender NSURLHandleClient NSURLProtocolClient NSXMLParserDelegate 
*/


Немає коментарів:

Дописати коментар