Skip to content

Instantly share code, notes, and snippets.

View marianomike's full-sized avatar

Mike Mariano marianomike

View GitHub Profile
import UIKit
class SecondViewController: UIViewController {
// reference the new text field
@IBOutlet weak var DisplayField: UITextField!
// create variable for new text field to display
var userText:String! = ""
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, UITextFieldDelegate, CLLocationManagerDelegate, MKMapViewDelegate {
// reference the user input field
@IBOutlet weak var inputText: UITextField!
override func viewDidLoad() {
function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
function colorFromString(value) {
var immutable = MSImmutableColor.colorWithSVGString_(value);
return MSColor.alloc().initWithImmutableObject_(immutable);
}
@import 'common.js'
var onRun = function(context) {
var sketch = context.api();
var doc = sketch.selectedDocument;
var sharedStyles = doc.sketchObject.documentData().layerStyles();
var numberOfSharedStyles = Number(sharedStyles.numberOfSharedStyles());
function updateAllExistingStyles(doc, styleID, sharedStyles, index){
//reference the pages array in the document
var pages = doc.sketchObject.pages();
for (var i = 0; i < pages.count(); i++){
//reference each page
var page = pages[i];
//reference the artboards array of each page
var artboards = [page artboards];
for (var k = 0; k < sharedStyles.numberOfSharedStyles(); k++){
var layerStyle = sharedStyles.objects().objectAtIndex(k);
var styleName = String(layerStyle.name());
//checks if the name of the imported color is the same as the existing
if(styleName == colorName){
var fill = layerStyle.value().fills().firstObject();
var oldFill = String("#" + fill.color().immutableModelObject().hexValue());
//create a new style with fill and add it to the shared styles list
var style = MSStyle.alloc().init();
var fill = style.addStylePartOfType(0);
fill.color = colorFromString(colorValue);
sharedStyles.addSharedStyleWithName_firstInstance(colorName,style);
function checkIfExists(colorName, existingStyles){
var existsArray = [];
for (var i = 0; i < existingStyles.length; i++){
if(existingStyles[i] == colorName){
existsArray.push(colorName);
}
}
if(existsArray.length > 0){
return true;
for(var i = 0; i < palette.length; i++){
for(var z = 0; z < palette[i].length; z++){
//get the values we need from the palette array
var colorName = palette[i][z].name;
var colorValue = palette[i][z].value;
}
}
var sketch = context.api();
var doc = sketch.selectedDocument;
var sharedStyles = doc.sketchObject.documentData().layerStyles();
var numberOfSharedStyles = Number(sharedStyles.numberOfSharedStyles());
//create array to hold existing styles for reference later
var existingStyles = [];
//if there are exisitng styles push them to array