自定义构造方法
来源:互联网 发布:重装mac os x系统 编辑:程序博客网 时间:2024/05/13 06:51
ios中,自定义构造方法
Student.h
#improt<Foundation/Foundation.h>
@interface Student:Object{
int _age;
}
-(void)setAge:(int)age;
-(int)age;
@end
Student.m
#import "Student.h"
@implement Student
-(void)setAge:(int)age{
_age = age;
}
-(void)age{
return age;
}
@end
在main文件中,只需要实例化它就可以进行使用了
//核心
Student *student = [[Student all]init];//为其分配内存也可以说是实例化
student.age = 12;
以上是在外部文件进行自定义函数
在文件内部进行函数自定义:
调用:
[self initWithTitle:@"Hello World" initWithAuthor:@"Lin" initWithAge:10]
//方法体
-(instancetype)initWithTitle:(NSString*)title initWithAuthor:(NSString*)author initWithAge:(NSInteger*)age{
self.title = title;
self.author = author;
self.age = age;
}
跟JAVA 的不同点:
在java中写个构造方法(函数)直接写就行了
public setAge( int age){
return age;
}
0 0
- 构造方法,自定义构造方法
- 自定义构造方法
- 自定义构造方法
- ios自定义构造方法
- 自定义构造方法
- 自定义构造方法
- 82,自定义构造方法
- 自定义构造方法
- 自定义view构造方法
- 构造方法之自定义构造方法
- Objective-C - 自定义构造方法
- Objective-C 自定义构造方法
- Object-c------自定义构造方法
- 自定义View的构造方法
- 自定义view之构造方法
- 自定义view的构造方法
- 自定义view-构造方法和自定义属性
- 05自定义构造方法和description方法
- 按字节截取字符串 (有汉字)
- 单点登录原理和java实现简单的单点登录
- [Win32] API Hook(2)在64位系统上的实现
- 欢迎使用Markdown编辑器写博客
- 几个名词概念
- 自定义构造方法
- POSIX多线程程序设计(第3章:同步)
- AndroidWear 支持语音输入的通知
- 完美解决Google最新的Design:TabLayout结合ViewPager无法显示Icon的问题
- 【算法学习笔记】-排序算法
- Webpower中国区发布《2015年中国酒店旅游行业邮件营销市场报告》
- Python图像处理库:Pillow 初级教程
- 基础总结篇之五:BroadcastReceiver应用详解
- python学习--核心编程3习题解答以及知识点记录