当前位置:网站首页>Swift notes
Swift notes
2022-06-30 00:28:00 【LAOning11】
1 How to convert data into their own enumeration values
rawValue be used for swift Medium enum( enumeration ), Used to get the original value of the enumeration item
// enumeration Be careful WirelessType:Int Int To write
enum WirelessType:Int {
case addition
case substraction
case multiplication
case division
}
let sourceArr = ["1","3","2"];
// Get the value and convert it to string
let numberString = sourceArr[1] as! String;
// take string Turn it into int (?? 5) Set the default value to 5
let number = Int(numberString) ?? 5;
//rawValue: according to mmm Get the corresponding enumeration value
let number_Emum = WirelessType(rawValue: number);
if number_Emum == WirelessType.multiplication {
print(" Is to put the data ");
}
2 Judge local value (UserDefaults) Whether there is
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 establish tableview( Do not register method )
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 Use masonary
let addView = UIView.init();
self.view.addSubview(addView);
addView.mas_makeConstraints {
(make: MASConstraintMaker? ) in
make?.width.equalTo()(100);
};
5 swift Use in oc Of block
OC Callback
@property (nonatomic,copy) void(^changeSelectBlock)(NSString *nowSelectCode);
@property (nonatomic,copy) void(^changeSelectBlock_New)(NSString *nowSelectCode,NSString *nowSelectCodeTwo);
swift Use
collectionScreenView.changeSelectBlock = {
nowSelectCode in
};
collectionScreenView.changeSelectBlock_New = {
nowSelectCode , nowSelectCodeTwo in
};
6 Get the corresponding class according to the class name
// You need to splice the project file name in front
let workName = Bundle.main.infoDictionary?["CFBundleExecutable"] as! String
let className: String = workName + "." + " Class name ";
guard let class_VC = NSClassFromString(className) as? UIViewController.Type else{
// No corresponding class !
return;
}
// Instantiate a
let vc = class_VC.init()
边栏推荐
- vsftp 与 TFTP 与 samba 与 nfs 复习
- 蛇形矩阵(数组模拟方向, d代表转弯)
- 01 backpack problem
- 单位固定资产怎么管理,行政单位的固定资产应该怎么管理
- Mysql:sql overview and database system introduction | dark horse programmer
- 网络方向哪个发展更好?数据通信工程师学习路线分享
- MySQL基础2
- 公司固定资产该哪个部门管理,一般公司固定资产怎么管理
- Three postures of anti CSRF blasting
- VIM plug in manager VIM plug installation method
猜你喜欢

Five key elements of the data center

Sword finger offer II 035 Minimum time difference

剑指 Offer II 037. 小行星碰撞

传统微服务框架如何无缝过渡到服务网格 ASM

Root cause of glideexception: failed decodepath{directbytebuffer- > gifdrawable- > drawable}

Can't recognize the original appearance

关联性——典型相关分析

初始I/O及其基本操作

网络方向哪个发展更好?数据通信工程师学习路线分享

JS的初步语法
随机推荐
Use of shortcut keys for idea tools
MySQL基础2
HDCP Paring
固定资产管理系统多少钱,固定资产管理系统价格
《性能之巅第2版》阅读笔记(四)--Memory监测
Connection query of SQL Server database
Automatic integration: yescomusa, an overseas cross-border e-commerce, cooperates with cloud expansion to realize one-stop Automation Service
01背包问题
[advanced C language] file operation (I)
What does it mean to open an account online? In addition, is it safe to open an account online now?
Solr basic operation 16
MySQL基础3
[PHP] PHP variable memory release
Serpentine matrix (array simulates direction, D represents turning)
Solr basic operation 8
Root cause of glideexception: failed decodepath{directbytebuffer- > gifdrawable- > drawable}
MySQL foundation 3
Getting started with qpainter: drawing the chess interface
Review of vsftp, TFTP, samba and NFS
IO stream summary