如果晚上月亮升起的时候,月光照到我的门口,我希望月光女神能满足我一个愿望,我想要一双人类的手。我想用我的双手把我的爱人紧紧地拥在怀中,哪怕只有一次。如果我从来没有品尝过温暖的感觉,也许我不会这样寒冷;如果我从没有感受过爱情的甜美,我也许就不会这样地痛苦。如果我没有遇到善良的佩格,如果我从来不曾离开过我的房间,我就不会知道我原来是这样的孤独.

学习Objective-C笔记

上一篇 / 下一篇  2015-04-27 10:09:04 / 个人分类:Objective-C

 
    想学习IOS APP开发没有Mac ox,不能用Xcode,用虚拟机装MacOS搞不定的,单单只是为了学习Objective-C开发语言,VMware+Linux、Windows+CodeBlocks就满足了,看看敬佩的IOS APP是怎么开发的,开发难易程度。
 
在VMware下安装Linux(ubuntu,startOS...)这个不说了,安装Objective-C可以百度解决
  
下面进入实例:
1.我的第一个Objective-C代码:hello.m
 
#import <Foundation/Foundation.h>
8Dg.s H2xt6Q?0int main(int argc,const char *argv[])51Testing软件测试网NV X|%Ea^ ^h
{
j1mx$Sq5r(Ka0 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
c+l8} tXt'`0 NSLog(@ "hello world");51Testing软件测试网 LcP C$S'o,P2V7p
 NSLog(@"welcome to IOS Training Center!");
U C*T V]!Dm{0 [pool drain];51Testing软件测试网#VC6{&dR*e E u
 return 0;
6_;pmRk)p0}
# 瞬间眼睛亮了,这不是C! 像又不像!:):(  确实有C的成分,Objective-C就包含C,这样看来学起来就没那么难了,搞软件的都学过C,其中的include-->import,stdio.h-->Foundation.h,print()-->NSlog()
 
写完上面的代码之后要怎么编译,我将编译语句写成Shell了方便使用,请看下面的编译代码:
 
#将下面的代码写进makefile文件
#/bin/bash/sh51Testing软件测试网e,q:KBh4[s g,Q
gcc $1 $(gnustep-config --objc-flags) -lobjc -lgnustep-base -o $2
(E"q6rC-e5mz vmr"g0rm -rf *.d
 
执行过程:
./makefile hello.m hello
#hello.m是源代码  hello是编译后可执行文件
运行:
./hello
 
输出:
2015-04-27 10:30:15.631 hello[2368] hello world51Testing软件测试网,[7\a x0}!r
2015-04-27 10:30:15.635 hello[2368] welcome to IOS Training Center!
 
2.objective-c中的很多东西都和C一样:函数,方法等
下面看看For循环,完全和C一样这样用起来就很上手
 
#import <Foundation/Foundation.h>
int main(int argc, const char *argv[])
@6a0i[:P"ai&sd0{51Testing软件测试网w4t$O+I?)cK
    int count=10;
N1B/\0}e7[5g `0    NSLog (@"The number is 1 to count.");
_1T!hA9h'L0    int i;51Testing软件测试网a_$EV+`'ZE_ W/B
    for (i=1;i<=count;i++){51Testing软件测试网&J4MMLK-F!Q
        NSLog(@"i=%d\n",i);
(L PwR2z*F Lf-dD g-{0    }
    return 0;51Testing软件测试网a#FK n(Q-v_
}#输出结果就不展示了,结果一目了然了。
 
 
3.读文件:Fopen
#代码功能:实现计算文件中每行字符长度
#import <Foundation/Foundation.h>
-V-S_pdE|v0 51Testing软件测试网#T\/Rn+d
 int main(int argc,const char *argv[])51Testing软件测试网{/H.vOMX}R#e
 {51Testing软件测试网-e B5kU$}'R+?I
 FILE *wordfile = fopen("/home/wind/Objective-c/words.txt","r");
HD`wM F-l0 char word[100];51Testing软件测试网 ] W.R h;}M|R8}u
 
R(G}j0k4ajRi0 while(fgets(word,100,wordfile))
9GdO `l c9G_0 {
J_b-lNX0     word[strlen(word)-1]='\0';
{tW4B ^:xA0     NSLog(@"%s is %d characters long.",word,strlen(word));
^;~+Pz2L/Nj0 
'f!QS%^t|VL0 }
Yv7b&|$QFU0 fclose(wordfile);
/qA;sLfA9}0 return (0);51Testing软件测试网#jKW H1a9x e
 }
今天就到这里把 后续在续...
 
 

TAG:

 

评分:0

我来说两句

Open Toolbar