Swift在 iOS 13上获取Wi-Fi SSID(服务集标识)
Apple在iOS 13进行了很多更改,以保护使用iOS用户的隐私。其中包括了网络上的更改,这样会导致我们的应用程序有些服务不能使用。CNCopyCurrentNetworkInfo是用来获取Wi-Fi信息的。可以通过下面示例的方法获取Wi-Fi的SSID:import Foundationimport SystemConfiguration.CaptiveNetworkfunc getWiFiS
Apple在iOS 13进行了很多更改,以保护使用iOS用户的隐私。其中包括了网络上的更改,这样会导致我们的应用程序有些服务不能使用。CNCopyCurrentNetworkInfo是用来获取Wi-Fi信息的。可以通过下面示例的方法获取Wi-Fi的SSID:import Foundationimport SystemConfiguration.CaptiveNetworkfunc getWiFiS
是不能直接在异步调用返回数据,一种替代的方案是向异步调用的函数里传入回调函数,当异步任务完成后,使用回调函数处理结果。Swift 3示例:class func getData(completionHandler: @escaping (data: NSArray) -> ()) {...let task = session.dataTask(with:url) { data, resp
Swift 3/4获取AppDelegate实例:func appDelegate() -> AppDelegate{ return UIApplication.shared.delegate as! AppDelegate}对于Swift < 3func appDelegate() -> AppDelegate{ return UIApplication.share
禁止UITableView选中高亮,可以对UITableViewCell实例设置样式:Swift 2cell.selectionStyle = UITableViewCellSelectionStyle.None Swift 3cell.selectionStyle = .none
给UIImage添加extension(兼容Swift3 和Swift 4)extension UIImage { func scaled(withSize size: CGSize) -> UIImage { &nbs
Swift 2,3,4在语法上少有不同,以下是各个Swift版本修改取消按钮文本颜色的代码片段Swift 4.0let cancelButtonAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white] UIBarButtonItem.appearan
使用xcode创建swift项目,你需要知道在项目中正在使用的swift版本。使用终端查看:swift -version 比较稳妥的方法是在xcode上查看,因为每个项目可能设定的swift 版本不一样。按路径打开:Project -> 选择项目的target -> Build Settings ->
新安装Xcode 9.2 (9C40b),上传app到App Store时报错:ERROR ITMS-90534: "Invalid Toolchain. New apps and app updates must be built wit
Swift随着版本的升级,日期类都会有一点变化。所以各个版本的Swift日期和字符串的转换有所不同。Swift 4String转换为Datevar dateString = "2017-11-17" var dateFormatter = DateFormatter() // dateFormat
Swift 3升级到Swift 4,在使用#selector可能会报以下警告:Argument of '#selector' refers to instance method 'doAction()' in 'ViewController' that depends&
Reachability.swiftimport Foundation import SystemConfiguration class Reachability { var hostname: String? var isRunn
Xcode 9之后新增了拖拽的方式缩放iPhone模拟器。Xcode 9.1界面操作Menubar >> Window >> Physical Size 或 Pixel Accurate缩放快捷键⌘ 1:Physical Size,按物理尺寸缩放 
问题下载iOS 9.1模拟器失败,报错信息:Could not download and install iOS 9.1 Simulator. The certificate for this server is invalid. You&