我不确定这是否打破了xcode8 beta 5.看看这段代码.你认为首先应该打印"A",还是首先打印"B"?
let q = DispatchQueue(label: "q", attributes: .concurrent)
q.async(flags: .barrier) {
Thread.sleep(forTimeInterval: 0.25)
print("A")
}
q.sync {
print("B")
}
Run Code Online (Sandbox Code Playgroud)
因为.barrier,我认为它应该阻止并发队列并打印"A","B",但它不在最新的xcode beta中.
错误?对.barrier的误解?你怎么看?
请注意:我知道如果我使用串行队列,这将以预期的顺序打印 - 这是一个更大的系统的一小部分,我需要孤立地理解这种行为.
我刚刚在我的测试手机和XCode 8上更新了iOs10.我运行了代码迁移,并在我的模拟设备上成功运行了测试.
但是,一旦我开始尝试在我的真实设备上进行测试,事情就会停止顺利进行.在运行我的Sprite Kit游戏大约5到10秒后,它会崩溃并使手机无法运行,直到我从计算机上拔下它.拔掉它后,游戏正常运行,仍然非常流畅.
这是打印到控制台的启动通知:
2016-09-15 22:20:49.490959 AppName[411:38688] [DYMTLInitPlatform] platform initialization successful
2016-09-15 22:20:49.684189 AppName[411:38634] Metal GPU Frame Capture Enabled
2016-09-15 22:20:49.684758 AppName[411:38634] Metal API Validation Enabled
Run Code Online (Sandbox Code Playgroud)
这是手机插入电话后应用崩溃后收到的错误:
/BuildRoot/Library/Caches/com.apple.xbs/Sources/Metal/Metal-85.83/ToolsLayers/Debug/MTLDebugRenderCommandEncoder.mm:130: failed assertion `indexBufferOffset(12) + (indexCount(480) * 2) must be <= [indexBuffer length](960).'
(lldb)
Run Code Online (Sandbox Code Playgroud) 我在Alamofire.downloand中收到错误,如下所示:
Alamofire.download(URLString).responseData { response in
if let data = response.result.value {
let image = UIImage(data: data)
}else{
print(response.result.error)
}
}
Run Code Online (Sandbox Code Playgroud)
Alamofire.AFError.responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.inputFileReadFailed(文件:///private/var/mobile/Containers/Data/Application/40167F58-FF4A-4D19-B01A-F8ED90F794DD/tmp/CFNetworkDownload_1dnNQR.tmp)))
有人可以帮忙解决它或面临同样的问题吗?
谢谢
在对代码进行任何更改后,Xcode 8将构建项目中的每个目标.我重新启动Xcode后不会发生这种情况.在每次更改后开始构建所有目标之前,通常需要一些时间(20-60分钟).
到底是怎么回事?这非常烦人并且会导致生产力下降.在"首选项">"常规"中,我已选中 "显示实时问题"和"错误后继续构建" .
谢谢,-justColbs
我试图在Interface Builder中为我的标签选择"系统字体".所有这些标签都包含属性字符串.如果它们是"痛苦标签",我可以轻松选择"系统字体",我的应用程序将自动使用iOS 8的"Helvetica"和iOS 9+的"旧金山".
问题是,使用属性字符串时似乎不可能.(我需要它们用于线之间的间距).
即使我要下载字体并在界面构建器中选择一个字体,它也不会像"纯文本"标签那样根据iOS自动更改.
有没有办法实现这个目标?也许我错过了什么.
顺便说一句,我目前的工作是将所有标签连接到一个插座阵列并循环创建NSMutableAttributedString,然后用编程检索的系统字体"覆盖"字体属性.
这样做的缺点是标签创建了两次,因此在具有大量标签的屏幕上会变慢.
编辑:我用来"更改"字体的代码:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
for label in labelsToFormat {
let targetFont = UIFont.systemFont(ofSize: label.font.pointSize)
let originalLabel = NSMutableAttributedString(attributedString: label.attributedText!)
originalLabel.addAttribute(NSFontAttributeName, value: targetFont, range: NSMakeRange(0, originalLabel.length))
label.attributedText = originalLabel
}
for label in labelsToFormatBold {
let targetFont = UIFont.boldSystemFont(ofSize: label.font.pointSize)
let originalLabel = NSMutableAttributedString(attributedString: label.attributedText!)
originalLabel.addAttribute(NSFontAttributeName, value: targetFont, range: NSMakeRange(0, originalLabel.length))
label.attributedText = originalLabel
}
}
Run Code Online (Sandbox Code Playgroud) 当我的应用程序处于后台或被杀时,我想每1分钟获取一个新位置.这是我的代码:
定位服务:
class LocationService: NSObject, CLLocationManagerDelegate {
static let shared = LocationService()
var locationManager = CLLocationManager()
var significatLocationManager = CLLocationManager()
var currentLocation: CLLocation!
var timer = Timer()
var bgTask = UIBackgroundTaskInvalid
func startUpdatingLocation() {
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = kCLDistanceFilterNone
if #available(iOS 9.0, *) {
locationManager.allowsBackgroundLocationUpdates = true
}
locationManager.delegate = self
locationManager.startUpdatingLocation()
}
func stopUpdatingLocation() {
locationManager.stopUpdatingLocation()
timer.invalidate()
}
func restartUpdatingLocation() {
locationManager.stopMonitoringSignificantLocationChanges()
timer.invalidate()
startUpdatingLocation()
}
func startMonitoringLocation() {
locationManager.stopUpdatingLocation()
locationManager.startMonitoringSignificantLocationChanges()
timer.invalidate()
}
func changeLocationAccuracy(){
switch locationManager.desiredAccuracy { …Run Code Online (Sandbox Code Playgroud) 我使用swift 3,我有一个NSTableView(3列).我填写如下数据:
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
var cellIdentifier = String()
var cellText = String()
switch tableColumn {
case tablewView.tableColumns[0]?:
cellText = "100"
cellIdentifier = "Cell1"
break
case tablewView.tableColumns[1]?:
cellText = "100"
cellIdentifier = "Cell2"
break
case tablewView.tableColumns[2]?:
cellText = "100"
cellIdentifier = "Cell3"
break
default: break
}
if let view = tableView.make(withIdentifier: cellIdentifier, owner: nil) as? NSTableCellView {
view.textField?.stringValue = cellText
return view
}
return nil
}
Run Code Online (Sandbox Code Playgroud)
现在,我想在每次选择改变时对第1列的所有值求和.我怎么能意识到这一点?
我是xcode开发的新手,在尝试修改我自己项目的IBinspectable属性中的apple教程时,我遇到了一个主要的障碍.
我定义了一个简单的按钮子类:
import UIKit
@IBDesignable public class SocialMediaLoginButton: UIButton {
private var _loginType: SocialMediaLoginType = .facebook
@IBInspectable public var loginType: SocialMediaLoginType
= SocialMediaLoginType.facebook {
didSet {
self._loginType = loginType
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的故事板中添加了一个UIButton,然后我选择了CustomClass作为上面的类型.当我切换到属性检查器时,属性不适合我调整.我不知道发生了什么:
我已经查找了其他问题,但是在应用开发人员论坛上有极其过时或没有答案.
我试过了:
这些都没有奏效.我对如何解决这个问题感到茫然.我正在使用Xcode 8.3.3
我想用德语和日语翻译我的应用程序.我已经阅读了教程,但是我找不到我应该在我的应用程序的信息选项卡中查看的Base Internationalization框.我的信息选项卡中的主要部分是"自定义IOS目标属性","文档类型","导出的UTI"......没有任何关于本地化的信息.
我想我必须在"自定义IOS目标属性"中管理它,但我不知道如何.在那里,我添加了"Localizations"键和"English","German"和"Japanese"值,我还有一个关键的"Localization native development region",其值为"en".
然后我在Base.lproj中添加了我的Localizable.strings文件,但是在File Inspector中我只能看到"Base"和"English"作为Localization,没有关于德语和日语的内容.
我还注意到,当我进入编辑器>添加本地化时,我无法选择任何语言.
你看到了什么问题吗?
谢谢,
亚历克斯
xcode8 ×10
ios ×7
swift3 ×4
swift ×3
xcode ×2
alamofire ×1
cllocation ×1
fonts ×1
ios10 ×1
iphone ×1
localization ×1
macos ×1
sprite-kit ×1