Command SwiftCompile failed with a nonzero exit code Xcode 14 - ios

Unable to Archive the build using XCode 14 but working fine for Xcode 13. I need to upgrade the code for iOS 16. I am updating my own Pod and It has StringExtension.swift inside it:
func enumerateComponents(separatedBy separator: CharacterSet, groupingSeparators: Bool, invoking body: #escaping ((_ index: Int, _ component: String, _ separator: String, _ stop: inout Bool) -> Void)) -> Void {
self._enumerateComponents(separatedBy: separator, groupingSeparators: groupingSeparators, invoking: body)
}
When I am commenting the above method call it is allowing me to archive.
fileprivate func _enumerateComponents(separatedBy separator: CharacterSet, groupingSeparators: Bool, invoking body: #escaping ((_ index: Int, _ component: String, _ separator: String, _ stop: inout Bool) -> Void)) -> Void {
guard !self.isEmpty else {
return
}
var index = 0
var currentComponent: String = ""
var currentSeparator: String = ""
var isFinishingComponent = false
var stop = false
let finishComponent = { (evenIfBlank: Bool) in
if evenIfBlank || !currentComponent.isEmpty {
body(index, currentComponent, currentSeparator, &stop)
index += 1
currentComponent = ""
currentSeparator = ""
}
isFinishingComponent = false
}
for c in self.unicodeScalars {
guard !stop else {
return
}
if separator.contains(c) {
currentSeparator.unicodeScalars.append(c)
if groupingSeparators {
isFinishingComponent = true
}
else {
finishComponent(true)
}
}
else {
if isFinishingComponent {
finishComponent(true)
}
currentComponent.unicodeScalars.append(c)
}
}
finishComponent(isFinishingComponent)
}
Error:
4. While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for PUKit)
5. While running pass #4393683 SILFunctionTransform "AllocBoxToStack" on SILFunction "#$sSS5PKKitE20_enumerateComponents33_797666E2FD4D301A62EEB955A760B819LL11separatedBy18groupingSeparators8invokingy10Foundation12CharacterSetV_SbySi_S2SSbztctF05$sSS5a25E13_capitalizing33_797666defghiJ50LLySSAA24StringCapitalizationTypeOFySi_S2SSbztcfU_SSz_XxTf1nncn_n".
for '_enumerateComponents(separatedBy:groupingSeparators:invoking:)' (at /Users/deraj/Documents/PU/CHS/PKKiii/pukit/PUKit/Misc/Extensions/StringExtension.swift:98:17)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 swift-frontend 0x000000011292afe7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1 swift-frontend 0x000000011292a018 llvm::sys::RunSignalHandlers() + 248
2 swift-frontend 0x000000011292b600 SignalHandler(int) + 288
3 libsystem_platform.dylib 0x00007ff80a19cdfd _sigtramp + 29
4 swift-frontend 0x000000010eca7c7d (anonymous namespace)::Remangler::mangle(swift::Demangle::Node*, unsigned int) + 48413
5 swift-frontend 0x000000010db6dd58 swift::SILBuilder::createApply(swift::SILLocation, swift::SILValue, swift::SubstitutionMap, llvm::ArrayRef<swift::SILValue>, swift::OptionSet<swift::ApplyFlags, unsigned char>, swift::GenericSpecializationInformation const*) + 168
I can see _enumerateComponents function call in error log.

Related

Firebase fetching causes crash for some users

When I try to fetch user data from Firebase a crash occurs for some users, I can't reproduce this crash myself but I do have the following crash log:
0 Ski Tracker 0x77bf0 closure #1 in HistoryPresenter.downloadHistory(completionHandler:) + 4340857840 (HistoryPresenter.swift:4340857840)
1 Ski Tracker 0x86c8 closure #1 in FetchFromDatabase.fetchUserHistoryFromDatabase(uid:completionHandler:) + 4340401864 (<compiler-generated>:4340401864)
2 Ski Tracker 0x8604 thunk for #escaping #callee_guaranteed (#guaranteed FIRDataSnapshot) -> () + 4340401668 (<compiler-generated>:4340401668)
3 FirebaseDatabase 0x1df28 __92-[FIRDatabaseQuery observeSingleEventOfType:andPreviousSiblingKeyWithBlock:withCancelBlock:]_block_invoke + 120
4 FirebaseDatabase 0xbf94 __43-[FChildEventRegistration fireEvent:queue:]_block_invoke.11 + 80
5 libdispatch.dylib 0x24b4 _dispatch_call_block_and_release + 32
6 libdispatch.dylib 0x3fdc _dispatch_client_callout + 20
7 libdispatch.dylib 0x127f4 _dispatch_main_queue_drain + 928
8 libdispatch.dylib 0x12444 _dispatch_main_queue_callback_4CF + 44
9 CoreFoundation 0x9a6f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
10 CoreFoundation 0x7c058 __CFRunLoopRun + 2036
11 CoreFoundation 0x80ed4 CFRunLoopRunSpecific + 612
12 GraphicsServices 0x1368 GSEventRunModal + 164
13 UIKitCore 0x3a23d0 -[UIApplication _run] + 888
14 UIKitCore 0x3a2034 UIApplicationMain + 340
15 libswiftUIKit.dylib 0x35308 UIApplicationMain(_:_:_:_:) + 104
16 Ski Tracker 0x7160 main + 4340396384 (FriendView.swift:4340396384)
17 ??? 0x1f6938960 (Missing)
If I understand the crash log correctly the code which is causing the crash is within the fetchUserHistoryFromDatabase function:
func fetchUserHistoryFromDatabase(uid : String, completionHandler: #escaping([String : Any]?) -> Void ) {
ref?.child("users").child(uid).child("runData").observeSingleEvent(of: .value, with: { snapshot in
guard let result = snapshot.value as? [String:Any] else {
print("Error no rundata")
completionHandler(nil)
return
}
completionHandler(result)
})
}
This function is called from downloadHistory where potential nil values are handled:
private func downloadHistory(completionHandler: #escaping () -> Void) {
if let id = Auth.auth().currentUser?.uid {
FetchFromDatabase().fetchUserHistoryFromDatabase(uid : id, completionHandler: { [weak self] dict in
if dict != nil {
for run in dict! {
self?.determineTimeStamp(run : run)
}
if !(self!.tempDict.isEmpty) {
let sortedDict = self?.tempDict.keys.sorted(by: { $0 > $1 } )
self?.convertDictToArray(sortedDict: sortedDict!)
}
}
completionHandler()
}
)}
}
Any help here is greatly appreciated.
Remove the force unwrapping from your code. Every ! is an invitation for a crash.
private func downloadHistory(completionHandler: #escaping () -> Void) {
if let id = Auth.auth().currentUser?.uid {
FetchFromDatabase().fetchUserHistoryFromDatabase(uid : id, completionHandler: { [weak self] dict in
guard let self = self else {
completion()
return
}
if let dict = dict {
for run in dict {
self.determineTimeStamp(run : run)
}
if !self.tempDict.isEmpty {
let sortedDict = self.tempDict.keys.sorted(by: { $0 > $1 } )
self.convertDictToArray(sortedDict: sortedDict)
}
}
completionHandler()
}
)}
}
I notice a self! there dangerous, because a user could leave the calling context of the function and since the closure has a capture list of weak self, it should return nil but you are forcing it
try this
private func downloadHistory(completionHandler: #escaping () -> Void) {
if let id = Auth.auth().currentUser?.uid {
FetchFromDatabase().fetchUserHistoryFromDatabase(uid : id, completionHandler: { [weak self] dict in
guard let self = self else { completionHandler()
return }
if let safeDict = dict {
for run in dict {
self.determineTimeStamp(run : run)
}
if (self.tempDict.isEmpty) {
let sortedDict = self.tempDict.keys.sorted(by: { $0 > $1 } )
self.convertDictToArray(sortedDict: sortedDict)
}
}
completionHandler()
}
)}
}

Crash when calling completion handler for `UNUserNotificationCenter`

I'm working on an app that, when receiving a silent push notification; will make two networking calls to get some data, and then use that data to create a local push notification.
This mostly works great in the foreground and the background; with the exception of some occasional crashes that I'm having a difficult time diagnosing.
This is my full implementation for the delegate method that gets called when the silent push notification arrives:
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
print("Notification received!")
UNUserNotificationCenter.current().delegate = self
let id = updateNotificationID()
let payload = userInfo
guard let ship: String = payload["ship"] as? String else {
return
}
guard let node: String = payload["node"] as? String else {
return
}
guard let graph: String = payload["graph"] as? String else {
return
}
var groupName: String = ""
networkStore.scryForGroupInfo(ship: ship, graph: graph) { groupTitle in
if groupTitle == "" {
//one on one
} else {
//groupchat
groupName = groupTitle
}
networkStore.scryOnNotificationReceipt(ship: ship, node: node, graph: graph) { [self] messageString, author in
let content = UNMutableNotificationContent()
if groupName == "" {
//group chat
content.title = "New Message from \(author)"
let chatShipDict:[String: String] = ["ChatShip": author]
content.userInfo = chatShipDict
} else {
content.title = "\(author) posted in \(groupName)"
let chatShipDict:[String: String] = ["ChatShip": groupName]
content.userInfo = chatShipDict
}
//Don't show a notification for a chat that we're currently in
if airlockStore.selectedChannel != nil {
let author = "~"+author
if airlockStore.selectedChannel.channelShip == author || airlockStore.selectedChannel.channelName == groupName {
completionHandler(.noData)
return
}
} else {
//One on one chat
if groupName == "" {
let author = "~"+author
for channel in airlockStore.unPinnedChannelDataObjects {
if channel.channelShip == author {
notificationChannel = channel
}
}
} else {
//Group chat
for channel in airlockStore.unPinnedChannelDataObjects {
if channel.channelName == groupName {
notificationChannel = channel
}
}
}
}
content.body = messageString
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 2, repeats: false)
let request = UNNotificationRequest(identifier: "notification.id.\(id)", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { Error in
print("Showing Notification")
completionHandler(.newData)
}
}
}
}
The crashes seem to occur at the completionHandler(.newData) line.
Here's my stack trace:
Thread 10 name:
Thread 10 Crashed:
0 libdispatch.dylib 0x00000001a0b147b8 dispatch_group_leave.cold.1 + 36 (semaphore.c:303)
1 libdispatch.dylib 0x00000001a0ae0668 dispatch_group_leave + 140 (semaphore.c:0)
2 Pocket 0x000000010464333c partial apply for closure #1 in closure #1 in closure #1 in AppDelegate.application(_:didReceiveRemoteNotification:fetchCompletionHandler:) + 136 (AppDelegate.swift:137)
3 Pocket 0x00000001046419ac thunk for #escaping #callee_guaranteed (#guaranteed Error?) -> () + 44 (<compiler-generated>:0)
4 libdispatch.dylib 0x00000001a0adda84 _dispatch_call_block_and_release + 32 (init.c:1466)
5 libdispatch.dylib 0x00000001a0adf81c _dispatch_client_callout + 20 (object.m:559)
6 libdispatch.dylib 0x00000001a0ae7004 _dispatch_lane_serial_drain + 620 (inline_internal.h:2557)
7 libdispatch.dylib 0x00000001a0ae7c34 _dispatch_lane_invoke + 456 (queue.c:3862)
8 libdispatch.dylib 0x00000001a0af24bc _dispatch_workloop_worker_thread + 764 (queue.c:6589)
9 libsystem_pthread.dylib 0x00000001ecc7e7a4 _pthread_wqthread + 276 (pthread.c:2437)
10 libsystem_pthread.dylib 0x00000001ecc8574c start_wqthread + 8
You say you are making two different network calls.
Are you sure you are not calling the completion handler twice sometimes? Make sure it is only called once.

Crash when running collectionGroup query in Cloud Firestore (Swift)

I run a mobile app project using Swift, SwiftUI and Cloud Firestore where I need to find users based on their different settings/preferences. I have solved this by using a collectionGroup query. But sometimes (maybe 1 out of 10 times) the query crashes without any (for me) understandable error message. The composite indexes have been created using the http links provided from XCode.
This is the function I use:
func getUsersFromActivityPrefs(genders:[String], activities:[Int],skillScore_min:Int, skillScore_max:Int,completion:#escaping ([String]) -> ()) {
var matchUsers = [String]()
var count = 0
let db = Firestore.firestore()
for gender in genders {
for activity in activities {
let dbRef = db.collectionGroup("activity_preferences")
.whereField("gender", isEqualTo: gender)
.whereField("activityid", isEqualTo: activity)
.whereField("status", isEqualTo: true)
.whereField("skill_score", isGreaterThanOrEqualTo: skillScore_min)
.whereField("skill_score", isLessThanOrEqualTo: skillScore_max)
.limit(to: 100)
dbRef.getDocuments {( snap, err) in
count+=1
if err != nil {
print(err!.localizedDescription)
}
for i in snap!.documentChanges{
let uid = i.document.get("uid") as? String ?? ""
if uid != "" && !matchUsers.contains(uid) {
matchUsers.append(uid)
if matchUsers.count == 100 {
count = genders.count * activities.count
completion(matchUsers) //escaping completion handler
return
}
}
}
if count == genders.count * activities.count {
completion(matchUsers)
return
}
}
}
}
}
I have attached the trace log and the crash message from XCode. Im using the latest version of Firebase SDK and deployment target is iOS14.
This is the trace log I get:
thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x4f)
frame #0: 0x00007fff4b80dd66 AttributeGraphAG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, AGSwiftMetadata const*, bool*, long) + 322 frame #1: 0x00007fff4b81f1a5 AttributeGraphAGGraphGetValue + 203
frame #2: 0x00007fff55e7ffab SwiftUISwiftUI.DynamicBody.phase.getter : SwiftUI._GraphInputs.Phase + 27 frame #3: 0x00007fff55e80176 SwiftUISwiftUI.DynamicBody.updateValue() -> () + 294
frame #4: 0x00007fff55b9583a SwiftUIpartial apply forwarder for implicit closure #2 (Swift.UnsafeMutableRawPointer, __C.AGAttribute) -> () in implicit closure #1 (A1.Type) -> (Swift.UnsafeMutableRawPointer, __C.AGAttribute) -> () in closure #1 () -> (Swift.UnsafeMutableRawPointer, __C.AGAttribute) -> () in closure #1 (Swift.UnsafePointer<A1>) -> AttributeGraph.Attribute<A> in AttributeGraph.Attribute.init<A where A == A1.Value, A1: AttributeGraph.StatefulRule>(A1) -> AttributeGraph.Attribute<A> + 26 frame #5: 0x00007fff4b808d03 AttributeGraphAG::Graph::UpdateStack::update() + 505
frame #6: 0x00007fff4b809199 AttributeGraphAG::Graph::update_attribute(AG::data::ptr<AG::Node>, bool) + 335 frame #7: 0x00007fff4b80d8e8 AttributeGraphAG::Graph::value_ref(AG::AttributeID, AGSwiftMetadata const*, bool*) + 130
frame #8: 0x00007fff4b81f1f3 AttributeGraphAGGraphGetValue + 281 frame #9: 0x00007fff561aeeb7 SwiftUISwiftUI.GraphHost.updatePreferences() -> Swift.Bool + 39
frame #10: 0x00007fff55c9a8cf SwiftUISwiftUI.ViewGraph.updateOutputs(at: SwiftUI.Time) -> () + 95 frame #11: 0x00007fff5611310c SwiftUIclosure #1 () -> () in (extension in SwiftUI):SwiftUI.ViewRendererHost.render(interval: Swift.Double, updateDisplayList: Swift.Bool) -> () + 1308
frame #12: 0x00007fff56112327 SwiftUI(extension in SwiftUI):SwiftUI.ViewRendererHost.render(interval: Swift.Double, updateDisplayList: Swift.Bool) -> () + 343 frame #13: 0x00007fff55ba07de SwiftUIclosure #1 () -> () in SwiftUI._UIHostingView.requestImmediateUpdate() -> () + 62
frame #14: 0x00007fff562739ae SwiftUIreabstraction thunk helper from #escaping #callee_guaranteed () -> () to #escaping #callee_unowned #convention(block) () -> () + 14 frame #15: 0x0000000112ebd8ac libdispatch.dylib_dispatch_call_block_and_release + 12
frame #16: 0x0000000112ebea88 libdispatch.dylib_dispatch_client_callout + 8 frame #17: 0x0000000112eccf23 libdispatch.dylib_dispatch_main_queue_callback_4CF + 1152
frame #18: 0x00007fff203a8276 CoreFoundation__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 frame #19: 0x00007fff203a2b06 CoreFoundation__CFRunLoopRun + 2685
frame #20: 0x00007fff203a1b9e CoreFoundationCFRunLoopRunSpecific + 567 frame #21: 0x00007fff2b773db3 GraphicsServicesGSEventRunModal + 139
frame #22: 0x00007fff24660af3 UIKitCore-[UIApplication _run] + 912 frame #23: 0x00007fff24665a04 UIKitCoreUIApplicationMain + 101
frame #24: 0x000000010db84a5b Sparringmain at AppDelegate.swift:14:7 frame #25: 0x00007fff20257415 libdyld.dylibstart + 1
Attachments:
Crash in XCode 1
Composite index 2
func getUsersFromActivityPrefs(genders: [String], activities: [Int], skillScore_min: Int, skillScore_max: Int, completion: #escaping ([String]) -> Void) {
var matchUsers = [String]()
var count = 0
let db = Firestore.firestore()
let dispatch = DispatchGroup() // instantiate dispatch group outside loop
for gender in genders {
for activity in activities {
dispatch.enter() // enter group on each iteration
let dbRef = db.collectionGroup("activity_preferences")
.whereField("gender", isEqualTo: gender)
.whereField("activityid", isEqualTo: activity)
.whereField("status", isEqualTo: true)
.whereField("skill_score", isGreaterThanOrEqualTo: skillScore_min)
.whereField("skill_score", isLessThanOrEqualTo: skillScore_max)
.limit(to: 100)
dbRef.getDocuments {( snap, err) in
if let snap = snap {
count += 1
for doc in snap.documents {
if let uid = doc.get("uid") as? String,
!matchUsers.contains(uid) {
matchUsers.append(uid)
}
}
} else if let err = err {
print(err)
}
dispatch.leave() // always leave no matter what the db returned
}
}
}
/*
this is the group's completion handler and it's only
called once after all groups have entered and left
*/
dispatch.notify(queue: .main) {
completion(matchUsers)
}
}

Swift 2.2: Segmentation fault: 11

I am getting a segfault: 11 after updating to the latest version of Xcode (7.3). The code that is triggering this is:
private func makeScreenshots(points points_I: [[CGPoint]], frames frames_I: [[CGRect]], scale:CGFloat, completion: (screenshots: [[UIImage]]) -> Void) {
var counter: Int = 0
// use didSet as a responder to the completion handler,instead of a loop, ensuring nice sequential execution
var images: [[UIImage]] = [] {
didSet {
if counter < points_I.count {
internalScreenshotRow()
} else {
completion(screenshots: images)
}
}
}
// same code is used twice -> nested function
func internalScreenshotRow() {
makeScreenshotRow(points: points_I[counter], frames: frames_I[counter], scale: scale) { (screenshot) -> Void in
counter += 1
images.append(screenshot)
}
}
internalScreenshotRow() // start first run
}
private func makeScreenshotRow(points points_I: [CGPoint], frames frames_I: [CGRect], scale:CGFloat, completion: (screenshots: [UIImage]) -> Void) {
var counter: Int = 0
// use didSet as a responder to the completion handler,instead of a loop, ensuring nice sequential execution
var images: [UIImage] = [] {
didSet {
if counter < points_I.count {
internalTakeScreenshotAtPoint()
} else {
completion(screenshots: images)
}
}
}
// same code is used twice -> nested function
func internalTakeScreenshotAtPoint() {
takeScreenshotAtPoint(point: points_I[counter], scale: scale) { (screenshot) -> Void in
counter += 1
images.append(screenshot)
}
}
internalTakeScreenshotAtPoint() // start first run
}
The error being thrown by compiler is:
1. While emitting SIL for 'makeScreenshots' at /ScrollViewImager.swift:115:13
2. While emitting SIL for 'internalScreenshotRow' at /ScrollViewImager.swift:131:9
3. While silgen closureexpr SIL function #_TFFFE8BeamItUpPS_16ScrollViewImagerP33_22F49B169CD6FD663C230349D2C79AE615makeScreenshotsFT6pointsGSaGSaVSC7CGPoint__6framesGSaGSaVSC6CGRect__5scaleV12CoreGraphics7CGFloat10completionFT11screenshotsGSaGSaCSo7UIImage___T__T_L_21internalScreenshotRowFT_T_U_FGSaS5__T_ for expression at [/ScrollViewImager.swift:132:99 - line:135:13] RangeText="{ (screenshot) -> Void in
counter += 1
images.append(screenshot)
}"
The ScrollViewImager is an open source library for taking screenshots of scrollview Reference

Swift 1.2 "Cannot express tuple conversion" error

This method was working fine in the last stable version of Swift, but it won't compile in Swift 1.2:
final func rotateBlocks(orientation: Orientation) {
if let blockRowColumnTranslation:Array<(columnDiff: Int, rowDiff: Int)> = blockRowColumnPositions[orientation] {
for (idx, (columnDiff:Int, rowDiff:Int)) in enumerate(blockRowColumnTranslation) {
blocks[idx].column = column + columnDiff
blocks[idx].row = row + rowDiff
}
}
}
This line:
for (idx, (columnDiff:Int, rowDiff:Int)) in enumerate(blockRowColumnTranslation) {
Throws the following error:
"Cannot express tuple conversion "(index:Int, element:(columnDiff:Int,rowDiff:Int)) to "(Int, (Int, Int))"
Any ideas about what's going on here, and how to fix it?
I would use typealias to simplify, but the following compiles without error for me.
var row: Int = 0
var column: Int = 1
struct block {
var column: Int
var row: Int
}
var blocks = [block]()
enum Orientation { case Up; case Down; }
typealias Diff = (columnDiff: Int, rowDiff: Int)
typealias DiffArray = Array<Diff>
typealias DiffArrayDict = [Orientation: DiffArray]
var blockRowColumnPositions = DiffArrayDict();
func rotateBlocks(orientation: Orientation) {
if let blockRowColumnTranslation: DiffArray = blockRowColumnPositions[orientation] {
for (idx, diff) in enumerate(blockRowColumnTranslation) {
blocks[idx].column = column + diff.columnDiff
blocks[idx].row = row + diff.rowDiff
}
}
}
I ran into the same thing and was able to get this working by adding an element: label for the tuple:
for (idx, element: (columnDiff: Int, rowDiff: Int)) in enumerate(blockRowColumnTranslation) {
blocks[idx].column = column + element.columnDiff
blocks[idx].row = row + element.rowDiff
}
Looks like a Swift bug to me. More generally, this is busted:
let pair = (a: 1, b: 2)
// normally those named elements don't matter, this is fine:
let (x,y) = pair
// but add a bit of nesting:
let indexed = (index: 1, pair)
// and, error:
let (i, (x,y)) = indexed
// cannot express tuple conversion '(index: Int, (a: Int, b: Int))' to '(Int, (Int, Int))'
I'd try removing the type names from the array's tuple declaration (i.e. Array<(Int,Int)> instead of Array<(columnDiff: Int, rowDiff: Int)>), see if that helps.
In other, perhaps related, news, this appears to crash the 1.2 compiler:
let a: Array<(Int,Int)> = [(x: 1,y: 2)]
Thanks guys! I wound up just rewriting it as a for-loop.. it's not exciting but it seems to work okay:
final func rotateBlocks(orientation: Orientation) {
if let blockRowColumnTranslation:Array<(columnDiff: Int, rowDiff: Int)> = blockRowColumnPositions[orientation] {
for var idx = 0; idx < blockRowColumnTranslation.count; idx++
{
let tuple = blockRowColumnTranslation[idx]
blocks[idx].column = column + tuple.columnDiff
blocks[idx].row = row + tuple.rowDiff
}
}
}
final func rotateBlocks(orientation: Orientation) {
if let blockRowColumnTranslation = blockRowColumnPositions[orientation] {
for (idx, diff) in enumerate(blockRowColumnTranslation) {
blocks[idx].column = column + diff.colunmDiff
blocks[idx].row = row + diff.rowDiff
}
}
}

Resources