ios第四天-金沙1005

ios第四天_ios runtime1 整数浮点数如何加入到array中去?2 ==与nsarray提供的isequaltoarray:有什么区别?3 字符串@“234”转为整数4 实现一个utility类,提供计算阶乘‘计算a的b次方5 在其他,.m中使用utility6 类是否支持多继承?7 完善parent类实现init方法,init类初始化自己的成员完善child类的fun方法,在fun中调用父类f

整数浮点数如何加入到array中去?

==与nsarray提供的isequaltoarray:有什么区别?

字符串@“234”转为整数

实现一个utility类,提供计算阶乘计算ab次方

在其他,.m中使用utility

类是否支持多继承?

7  完善parent类实现init方法,init类初始化自己的成员完善child类的fun方法,在fun中调用父类fun方法(super关键字)

  完善parent/child类实现 dealloc方法,在 dealloc中释放成员变量

p autorelease]释放的基本原理是什么?

9  @property属性是否对外公开的?

10  @property属性支持哪些 modifier?

11  assign/copy/retain的区别?

12添加到array对对象引用计数的影响?

    set/dictionary是否也有影响?

13. arc中内存释放的基本原理是什么?
14. __weak__unsafe_unretained区别?示例说明







nsnumber

用nsnumber类来用面向对象的方法处理数字。如果你只需要简单的数字(而不是对象),用nsinterger类来操作有符号数(正数或者负数),用nsuinterger类来操作无符号数(正数或0),用cgfloat类和double来操作浮点数。
numberwithint:将一个整数值封装成一个nsnumber实例;
numberwithunsignedint:将一个无符号整数值(正数或0)封装成一个nsnumber实例;
numberwithfloat:将一个浮点数封装成一个nsnumber实例;
numberwithdouble:将一个double类型的数封装成一个nsnumber实例;
intvalue:从调用该函数的nsnumber实例中返回一个整型nsiteger类型值。
unsignedintvalue:从调用该函数的nsnumber实例中返回一个无符号整型nsiteger类型值。
floatvalue:从调用该函数的nsnumber实例中返回一个浮点数cgfloat类型值。
doublevalue:从调用该函数的nsnumber实例中返回一个双精度double类型值。



1.整数浮点数如何加入到array中去?


@implementation appdelegate

– (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions

{

  

   nsnumber *a=[nsnumbernumberwithfloat:3.890];   //nsnumber的使用

  nsnumber*b=([nsnumbernumberwithinteger:7]);

  nsarray *array=[[nsarrayalloc]initwithobjects:a,b,nil];

  nsarray *array2=[[nsarrayalloc]initwithobjects:a,b,nil];

  nslog(@”%@”,array);


 // override point for customization after application launch.

    return yes;

}

2013-07-25 19:54:33.456 fourday[706:11303] (

    “3.89”,

    7

)


2==与nsarray提供的isequaltoarray:有什么区别?


@implementation appdelegate

– (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions

{

 

   nslog(@”%d”,array2==array);   / /等号的值为0,就是说array2与array不相等,比较的是地址

  nslog(@”%d”,[array isequaltoarray:array2]);  //isequaltoarray:的值为1,就是说两数组的值相同,比较的是数组的内容

// override point for customization after application launch.

    return yes;

}


2013-07-25 19:54:33.457 fourday[706:11303] 0

2013-07-25 19:54:33.457 fourday[706:11303] 1

3.字符串@“234”转为整数


@implementation appdelegate

– (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions

{

   nsstring *str=@”234″;

   nslog(@”%d”,[strintvalue]);

// override point for customization after application launch.

    return yes;

}

2013-07-25 19:54:33.458 fourday[706:11303] 234

4. 实现一个utility类,提供计算阶乘计算ab次方

utility.h

#import

@interface utility :nsobject

-(double)fun:(double) a another:(double)b;

@end


utility.m


#import “utility.h”

@implementation utility

-(double)fun:(double)a another:(double)b

{

    double c=pow(a, b);

    return c;

}

@end


 appdelegate.m

@implementation appdelegate

– (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions

{

  

    utility *r=[[utility alloc]init];

   double m=[rfun:3.0 another:2.0];

   nslog(@”%f”,m);


 // override point for customization after application launch.

    return yes;

}



2013-07-25 19:54:33.458 fourday[706:11303] 9.000000


类是否支持多继承?

 在oc中类不支持多继承,同java一样,与c++不同


7  完善parent类实现init方法,init类初始化自己的成员完善child类的fun方法,在fun中调用父类fun方法(super关键字)

  完善parent/child类实现 dealloc 方法,在 dealloc 中释放成员变量


parent.h


#import

@interface parent :nsobject

@property  (assign)nsstring *c;

-(id)init;

-(void)fun:(int)b;

-(void)dealloc;

@end



parent.m


#import “parent.h”

@implementation parent

-(id)init

{

   if(self =[super init])//super父类

    {

        //default value

        self.c=[[nsstringalloc]initwithformat:@”this is init”];

    }

    return self;

}                              //转到父类定义的init

-(void)fun:(int)b

{

    b=5;

    nslog(@”%@”,@”this is fun parent”);

    

}

-(void)dealloc

{

    [super dealloc];

    [self.crelease];

}

@end

child.h


#import “parent.h”

@interface child : parent

-(void)fun:(int)a;

@end


child.m

#import “child.h”

@implementation child

-(void)fun:(int)a

{

    a=1;

    nslog(@”%@”,@”this is child”);

    [superfun:10];

}

@end

appdelegate.m


@implementation appdelegate

– (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions

{

   

    parent *p1=[[parentalloc]init];//在调用init是首先调转到父类的定义init中,执行父类的init定义

   child *p2=[[childalloc]init];

    [p1 fun:10];

    [p2 fun:7];

   nslog(@”%@”,p1.c);

    [p1 release];//在调用时首先转到父类的dealloc函数,先释放父类的成员变量,再将父类释放掉

    nslog(@”%@”,@”this “);

 // override point for customization after application launch.

    return yes;

}



2013-07-25 19:54:33.460 fourday[706:11303] this is fun parent

2013-07-25 19:54:33.461 fourday[706:11303] this is child

2013-07-25 19:54:33.461 fourday[706:11303] this is fun parent

2013-07-25 19:54:33.462 fourday[706:11303] this is init

2013-07-25 19:54:33.462 fourday[706:11303] this 


12 添加到array对对象引用计数的影响?

    set/dictionary是否也有影响?

@implementation appdelegate

– (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions

{

  

    nsstring *str2=[nsstring stringwithformat:@”this is”];

   int count=[str2retaincount];

   nslog(@”%d”,count);

   nsset *s=[[nsset alloc]initwithobjects:str2,nil];

    count=[str2retaincount];

   nslog(@”%d”,count);

    

    

    nsdictionary *dic3=[nsdictionary dictionarywithcontentsoffile:str2];

    count=[str2retaincount];

    nslog(@”%d”,count);

   


 // override point for customization after application launch.

    return yes;

}


2013-07-25 19:54:33.459 fourday[706:11303] 1

2013-07-25 19:54:33.459 fourday[706:11303] 2

2013-07-25 19:54:33.460 fourday[706:11303] 2

14. __weak

__unsafe_unretained
区别?示例说明

@implementation appdelegate

– (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions

{

  

   

    nsmutablestring *p=[nsmutablestring stringwithformat:@”%@“,@”test”]; //先创建一个对象,再进行复制进行了两次操作,所以值比下一个大一

    nsmutablestring __unsafe_unretained *str3=p;

    nsmutablestring __weak *str2=p;

    nslog(@”%ld”,cfgetretaincount((__bridgecftyperef)str2));

    nslog(@”%ld”,cfgetretaincount((__bridgecftyperef)str3));

    nslog(@”%@”,str2);

    nslog(@”%@”,str3);

    

    

   __strong nsstring *p2=[[nsstring alloc]initwithformat:@”%@“,@”text”];//申请空间,直接赋值,没有中间创建对象的过程,所以比上一个少一

   __weak nsstring *str4=p2;

    __unsafe_unretained nsstring *str5=p2;

    nslog(@”%ld”,cfgetretaincount((__bridgecftyperef)str4));//将强类型赋给弱类型和__unsafe_unretained类型,

    nslog(@”%ld”,cfgetretaincount((__bridgecftyperef)str5));//然后将强类型赋空值,弱类型地址改变为零,__unsafe_unretained类型不变

    p2=nil;

    nslog(@”%@”,str4);

    nslog(@”%@”,str5);


 // override point for customization after application launch.

    return yes;

}

2013-07-25 19:50:10.781 oneday[625:11303] 3

2013-07-25 19:50:10.782 oneday[625:11303] 3

2013-07-25 19:50:10.784 oneday[625:11303] 2

2013-07-25 19:50:10.784 oneday[625:11303] 2


p2nsstring *0x00000000

str4nsstring *0x00000000

str5__nscfstring *0x071900a0



“ ” 方法  [类名  函数名]

“-”方法   [实例化  函数名]



js555888金沙老品牌的版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由思创斯整理,转载请注明出处:https://ispacesoft.com/128499.html

(0)

相关推荐

  • ios 个人开发者账号转公司开发者账号还在吗_苹果开发者账号个人和公司的区别苹果开发者账号常见的分类为个人、公司和企业三种,其功能权益也有所不同。在费用上,个人和公司账号每年99美元,而企业账号每年要299美元。在协作人数上,个人账号就有所限制,限于1人(开发者自己),公司和企业则同时支持多人使用,可以创建团队、添加团队成员至开发者账号。因此当个人开发者账号满足不了需求时,可以通过“个人开发者账号转公司开发者账号”来实现。如何“个人开发者账号转公司开发者…

  • opengl颜色渐变_opengl shader目录 一.简介 二.效果演示 三.源码下载 四.猜你喜欢 零基础 opengl (es) 学习路线推荐 : opengl (es) 学习目录 >> opengl es 基础 零基础 ope

  • iphone开发者账号注册_开发者账号申请开发者账号注册地址填写避坑

  • ios遍历字典「终于解决」//不可变字典    nsdictionary*dict=@{@”key1″:@”value1″,@”key2″:@”value2″};    //遍历方法    [dictenumeratekeysandobjectsusingblock:^(idkey,idobj,bool*stop){      nsl

  • ios app上架_怎么让自己的app上架ios-最全的app上架教程不上架app store安装到手机调试测试,需要用到ios真机调试证书打包的ipa才能安装到非越狱的手机使用。201

  • 苹果越狱后添加源_越狱后怎么添加源

    苹果越狱后添加源_越狱后怎么添加源iphone.tgbus.com/cydiaiphone中文网官方源apt.25pp.compp助手源cydia.hackulo.us/   ipa同步补丁官方源installous和appsync但是现在貌似这个源关闭了m.360.cn/cydia/360手机卫士源,防垃圾短信,防…

  • ios之深度剖析uiscrollview的实现原理与阻尼动画[通俗易懂]一、前言uiscrollview是ios开发中不可或缺也是使用最多的基础组件,常用的feed流、pager、轮播图等等,都与其存在密不可分的联系。日常开发中,我们通常局限于必要的几个调用接口和代理,而不曾探究隐藏在几个简单接口背后的故事,比如:滚动视图如何在有限的区域内展示无限的内容?每一次在滚动区域触控屏幕会产生哪些反应?它在现实世界中又是怎样的物理形态?本文从基本的参数观测开始,以数学、物理学和优化方法中的一些基本方法和概念为工具,探索uiscrollvi

    2022年12月10日
  • 想用旧式ios通知横幅?试试这款新的插件如果你想用旧式ios通知横幅,那么你可以试试这款插件。ios10通知横幅的风格和ios7、8、9的完

发表回复

您的电子邮箱地址不会被公开。

联系金沙1005

关注“java架构师必看”公众号

回复4,添加站长微信。

附言:ispacesoft.com网而来。

关注微信
网站地图