Skip to content

Instantly share code, notes, and snippets.

@Tokuriku
Tokuriku / Clamp Velocity of an SKNode's PhysicsBody
Last active August 29, 2015 14:24
Clamp Velocity of an SKNode's PhysicsBody
/* Clamp Velocity */
// Set the initial parameters
let maxVelocity = CGFloat(100)
let deltaX = (self.physicsBody?.velocity.dx)!
let deltaY = (self.physicsBody?.velocity.dy)!
// Get the actual length of the vector with Pythagorean Theorem
let deltaZ = sqrt(pow(deltaX, 2) + pow(deltaY, 2))
@Tokuriku
Tokuriku / Count lines of code in Xcode project
Last active June 30, 2024 21:09 — forked from ccabanero/Count lines of code in Xcode project
Count lines of code in SWIFT Xcode project
1. Open Terminal
2. cd to your Xcode project
3. Execute the following when inside your target project:
find . -name "*.swift" -print0 | xargs -0 wc -l
@Tokuriku
Tokuriku / Remap Point
Last active August 29, 2015 14:13
Remapping a CGPoint for use with SKPhysicsJoints in a non CGPointZero anchorPoint Scene
//To be applied to the anchor point
func remapPoint(point: CGPoint) -> CGPoint {
let correctedX = point.x + self.size.width * self.anchorPoint.x
let correctedY = point.y + self.size.height * self.anchorPoint.y
return CGPoint(x: correctedX, y: correctedY)
}
@Tokuriku
Tokuriku / iOS Hardware Scanner
Last active July 27, 2023 09:39
Basic code to get the Hardware Model of an iOS device in Swift
func platform() -> String {
var size: UInt = 0
sysctlbyname("hw.machine", nil, &size, nil, 0)
var machine = [CChar](count: Int(size), repeatedValue: 0)
sysctlbyname("hw.machine", &machine, &size, nil, 0)
return String.fromCString(machine)!
}
func model() -> String {
let model = self.platform()
@Tokuriku
Tokuriku / universal-framework.sh
Last active September 2, 2020 10:59 — forked from cromandini/universal-framework.sh
Script to put in an Aggregate Target of a Framework in Xcode 6 to create a Universal Framework
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build