Skip to content

Instantly share code, notes, and snippets.

@hrules6872
hrules6872 / CustomLayout.java
Created February 23, 2017 23:01
Custom Viewgroup: onSaveInstanceState - onRestoreInstanceState http://trickyandroid.com/saving-android-view-state-correctly/
public class CustomLayout extends LinearLayout {
@SuppressWarnings("unchecked") @Override public Parcelable onSaveInstanceState() {
Parcelable saveInstanceState = super.onSaveInstanceState();
SavedState savedState = new SavedState(saveInstanceState);
savedState.childrenStates = new SparseArray();
for (int i = 0; i < getChildCount(); i++) {
getChildAt(i).saveHierarchyState(savedState.childrenStates);
}
return savedState;
@dominicthomas
dominicthomas / max_height_linear_layout.txt
Created December 8, 2016 12:23
Enables you to set a max height for a linear layout while also using wrap content.. this means the layout will be collapsable but also have height constraints!
public class MaxHeightLinearLayout extends LinearLayout {
private int maxHeightDp;
public MaxHeightLinearLayout(Context context) {
super(context);
}
public MaxHeightLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
@steipete
steipete / SpinlockTestTests.swift
Last active August 29, 2023 08:47 — forked from RomanTruba/Synchronization_test_iOS_SDK10
Updated for Xcode 8, Swift 3; added os_unfair_lock
//
// SpinlockTestTests.swift
// SpinlockTestTests
//
// Created by Peter Steinberger on 04/10/2016.
// Copyright © 2016 PSPDFKit GmbH. All rights reserved.
//
import XCTest
@steipete
steipete / ios-xcode-device-support.sh
Last active December 12, 2023 03:36
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
@juliengdt
juliengdt / lowpower_mode.md
Last active August 26, 2023 18:26
Detect and make your iPhone app responds to low-power mode

Low Power Mode - LPM

With iOS 9 Apple added a Low Power Mode to the iPhone. It extends battery life by stopping some battery heavy features such as email fetch, Hey Siri and background app refresh until you can recharge the device.

It is important to understand that it is the user who decides to enter low power mode. You need to go into the battery settings to turn it on.

Detection

To detect LPM you have to be in the couple iOS 9.X / iPhone:

  • For iOS 8.X, you need test availablity before use it
@zacwest
zacwest / ios-font-sizes.swift
Last active May 4, 2024 13:41
iOS default font sizes - also available on https://www.iosfontsizes.com
let styles: [UIFont.TextStyle] = [
// iOS 17
.extraLargeTitle, .extraLargeTitle2,
// iOS 11
.largeTitle,
// iOS 9
.title1, .title2, .title3, .callout,
// iOS 7
.headline, .subheadline, .body, .footnote, .caption1, .caption2,
]
@natecook1000
natecook1000 / nshipster-new-years-2016.md
Last active July 10, 2018 19:24
NSHipster New Year's 2016

Greetings and salutations, NSHipsters!

As the year winds down, it's a tradition here at NSHipster to ask you, dear readers, to offer up your favorite tricks and tips from the past year as gifts to your fellow hipsters. With iOS 9, El Capitan, brand new watch- and tvOS's, and the open-sourcing of some minor Apple-related tech, there's bound to be lots to share.

Submit your favorite piece of Swift or @objc trivia, helpful hints, unexpected discoveries, useful workarounds, useless fascinations, or anything else you found cool this year. Just comment below!

If you need inspiration, try [the list from last year][2015], or [from the year before][2014], or [from the year before that][2013].

@phatblat
phatblat / gist:0dd175b406cf2f3fbfc9
Created August 26, 2015 01:22
xcodebuild -exportOptionsPlist available keys (Xcode 7b6)
Available keys for -exportOptionsPlist:
compileBitcode : Bool
For non-App Store exports, should Xcode re-compile the app from bitcode? Defaults to YES.
embedOnDemandResourcesAssetPacksInBundle : Bool
For non-App Store exports, if the app uses On Demand Resources and this is YES, asset packs are embedded in the app bundle so that the app can be tested without a server to host asset packs. Defaults to YES unless onDemandResourcesAssetPacksBaseURL is specified.
@Sloy
Sloy / MockParcel.java
Created February 26, 2015 12:50
MockParcel for testing Parcelables implementations with the new Android's Unit testing support (http://tools.android.com/tech-docs/unit-testing-support). Only String and Long read/write implemented here. Add mock methods for other types.
import android.os.Parcel;
import java.util.ArrayList;
import java.util.List;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doAnswer;
@rbsgn
rbsgn / TC agent as a service with Xcode 6.md
Last active October 25, 2020 21:25
TeamCity build agent as a launchd service done right

There are several complaints regarding TeamCity build agent can't run tests in iOS Simulator all gathered in issue TW-38954 Agent started automatically on Yosemite could not launch iOS simulator.

Official workaround from JetBrains found on StackOverflow for this issue looks like this:

$ sh buildAgent/bin/agent.sh start

This means we should convert from automatic launch by launchd to manual via Terminal.app. Side effect of this is no relaunch on agent crash or system reboot.

Further investigation on that issue has led me to the Apple Developer Forums topic where Apple engineer claims following about xcodebuild: