iOS学习——第四天

1.整数、浮点数如何加入到array中去?(NSNumber)

2.==  与NSArray提供的isEqualToArray有什么区别

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

4.实现一个utility类,提供计算阶乘‘计算a的b次方

5.在其他,.m中使用Utility

6.类是否支持多继承?

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

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

8.[p autorelease] 释放的基本原理是什么? :[p autorelease] 会把p加到autoreleasepool的队列中,到下次循环调用Drain,把队列中所有的对象释放

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

10. @property 属性支持哪些 modifier?  :retain nonatomic weak strong assigncopy

11. assign/copy/retain的区别? 

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

set/dictionary是否也有影响?

13.ARC中内存释放的基本原理是什么? :在适当的位置插入release

14.__weak与__unsafe_unretained区别?示例说明


//  Utility.h

#import<Foundation/Foundation.h>


@interface Utility :NSObject

+(long)JieCheng:(int) num;

//+(long)JieCheng2:(int) num;

+(int)BCiFang:(int)a bValue:(int)b;

@end


//  Utility.m

#import"Utility.h"


@implementation Utility

+(long)JieCheng:(int) num

{

    int s1=1;

    while (num>0) {

        s1=s1*num--;

    }

    return s1;

   //NSLog(@"%d的阶乘 %d",num,s1);

}

+(int)BCiFang:(int)a bValue:(int)b

{

    int s2=pow(a,b);

    return s2;

   //NSLog(@"%d%d次方 %d",a,b,s2);

}


@end


//  AppDelegate.m

#import"AppDelegate.h"

#import"Utility.h"


@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

   // Override point for customization after application launch.

    //1

    int a=10;

    float b=12.12;

    NSNumber *num1=[NSNumber numberWithInt:a];

    NSNumber *num2=[NSNumber numberWithFloat:b];

    NSArray *arr=[[NSArray alloc]initWithObjects:num1,num2,nil];

    NSLog(@"%@",arr);

    //2

    NSArray *arr2=[[NSArray alloc]initWithObjects:num1,num2,nil];

    if([arr isEqualToArray:arr2])

    {

        NSLog(@"1");

    }

    if(arr==arr2)

    {

        NSLog(@"2");

    }

   //isEqualToArray比较的是Array里的内容,==比较的是地址

    //3

    NSString *str=@"234";

    int c=[str intValue];

    NSLog(@"%d",c);

   //4.5

    int num=10;

    long s1=[Utility JieCheng:num];

    NSLog(@"%d的阶乘 %ld",num,s1);

    int a1=3,a2=5;

    int s2=[Utility BCiFang:a1 bValue:a2];

    NSLog(@"%d%d次方 %d",a1,a2,s2);

   //6不支持

    

   returnYES;

}


//7.8

//Parent.h

#import"Parent.h"


@implementation Parent

-(void)fun:(int)num

{

   NSLog(@"I'm parent");

}

- (id)init

{

   self = [superinit];//[super init]再初始成员变量先父类后子类

    if (self) {

       self.a=[NSMutableStringstringWithFormat:@"string_a"];

       self.b=[NSMutableStringstringWithFormat:@"string_b"];

    }

   returnself;

}


- (void)dealloc

{

    

    [self.release];

    [self.release];

    [superdealloc];

}


@end

dealloc


init



//day4-12对象的引用计数加1

   NSMutableString *s1=[NSMutableStringstringWithFormat:@"%@",@"One"];

    NSLog(@"%d",[s1retainCount]);

   NSMutableString *s2=[NSMutableStringstringWithFormat:@"%@",@"Two"];

    NSSet *set=[[NSSet alloc] initWithObjects:s1,s2, nil];

   NSLog(@"%d",[s1retainCount]);

    [s1 release];

   NSLog(@"%d",[s1retainCount]);

   NSDictionary *dic=[NSDictionarydictionaryWithObjectsAndKeys:s1,s2,nil];

   NSLog(@"%d",[s1retainCount]);


//day4-14

__strongNSString *str=[[NSStringalloc]initWithFormat:@"test"];

    __weak NSString *weak=str;

   __unsafe_unretainedNSString *un=str;

    str=nil;

    NSLog(@"%@",str);

   NSLog(@"%@",weak);//变为nil,调用其相关方法也不会有什么问题,编译器会处理

   NSLog(@"%@",un);//指针变为野指针,调用其相关方法会有危险


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值