当前位置:网站首页>swift笔记
swift笔记
2022-06-30 00:12:00 【LAOning11】
1 如何将数据转换成自己枚举值
rawValue 用于swift中的enum(枚举),用于取枚举项的原始值
//枚举 注意WirelessType:Int Int 要写上
enum WirelessType:Int {
case addition
case substraction
case multiplication
case division
}
let sourceArr = ["1","3","2"];
//获取值转换成string
let numberString = sourceArr[1] as! String;
//将string转化成int (?? 5)将默认值设为5
let number = Int(numberString) ?? 5;
//rawValue: 根据mmm获取对应枚举值
let number_Emum = WirelessType(rawValue: number);
if number_Emum == WirelessType.multiplication {
print("就是就是将数据");
}
2 判断本地值(UserDefaults)是否存在
let loginMessage:Optional<NSDictionary> = UserDefaults.standard.value(forKey: "loginMessage") as? NSDictionary;
if !(loginMessage == nil) {
username = loginMessage?["loginName"] as! String;
password = loginMessage?["password"] as! String;
}
3创建tableview(不注册方法)
var cell:LTextViewRTextView_Rebuild!
if tableView.dequeueReusableCell(withIdentifier: "cell") == nil {
cell = LTextViewRTextView_Rebuild(style: .subtitle, reuseIdentifier: "cell");
}else{
cell = (tableView.dequeueReusableCell(withIdentifier: "cell") as! LTextViewRTextView_Rebuild);
}
return cell;
4 swift 使用masonary
let addView = UIView.init();
self.view.addSubview(addView);
addView.mas_makeConstraints {
(make: MASConstraintMaker? ) in
make?.width.equalTo()(100);
};
5 swift中使用oc的block
OC回调
@property (nonatomic,copy) void(^changeSelectBlock)(NSString *nowSelectCode);
@property (nonatomic,copy) void(^changeSelectBlock_New)(NSString *nowSelectCode,NSString *nowSelectCodeTwo);
swift使用
collectionScreenView.changeSelectBlock = {
nowSelectCode in
};
collectionScreenView.changeSelectBlock_New = {
nowSelectCode , nowSelectCodeTwo in
};
6 根据类名获取对应类
//需要在前面拼接项目文件名
let workName = Bundle.main.infoDictionary?["CFBundleExecutable"] as! String
let className: String = workName + "." + "类名";
guard let class_VC = NSClassFromString(className) as? UIViewController.Type else{
//没有对应类!
return;
}
//实例化一个
let vc = class_VC.init()
边栏推荐
- Root cause of glideexception: failed decodepath{directbytebuffer- > gifdrawable- > drawable}
- QT learning 04 Hello QT
- TP5查询AND和OR条件嵌套
- What is IGMP? What is the difference between IGMP and ICMP?
- Solr基础操作13
- gyctf_ 2020_ document
- 克隆無向圖[bfs訪問每條邊而不止節點]
- After crossing, she said that the multiverse really exists
- JVM之栈空间
- 手机开户后多久才能通过?另外,手机开户安全么?
猜你喜欢

蛇形矩阵(数组模拟方向, d代表转弯)

js中的事件

AI chief architect 9- huxiaoguang, propeller model library and industry application

基于zfoo开发项目的一些规范

JS draw polar color gradient
![多数元素II[求众数类之摩尔投票法]](/img/8f/5925f97c0f5f8c50c19a9ef6d7723c.png)
多数元素II[求众数类之摩尔投票法]

Review of vsftp, TFTP, samba and NFS

After crossing, she said that the multiverse really exists

QT learning 03 birth and essence of QT

Koa2 learning and using
随机推荐
What is IGMP? What is the difference between IGMP and ICMP?
Will the flush SQL CDC parallelism affect the order? Generally, only 1 can be set for data synchronization.
Stack space of JVM
History of deep learning
Solr basic operation 11
Connection query of SQL Server database
What is flush software? Is it safe to open an account online?
Basic tutorial for installing monggodb in win10
Introduction to reptiles: data capture of Betta barrage, with 11 introductory notes attached
视频ToneMapping(HDR转SDR)中的颜色空间转换问题(BT2020转BT709,YCbCr、YUV和RGB)
Solr basic operation 8
将日志文件存储至 RAM 以降低物理存储损耗
Leetcode (76) -- Minimum Covering substring
蛇形矩阵(数组模拟方向, d代表转弯)
Some specifications based on zfoo development project
Golang6 reflection
Solr basic operations 7
Machine learning: the concept and application of VC dimension
Leetcode (633) -- sum of squares
Label Troubleshooting: unable to open the marked image