{"kind":"article","variants":[{"paths":["\/documentation\/slothcreator\/gettingstarted"],"traits":[{"interfaceLanguage":"swift"}]}],"schemaVersion":{"major":0,"minor":3,"patch":0},"identifier":{"interfaceLanguage":"swift","url":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/GettingStarted"},"primaryContentSections":[{"kind":"content","content":[{"level":2,"type":"heading","text":"Overview","anchor":"Overview"},{"type":"paragraph","inlineContent":[{"type":"text","text":"Sloths are complex creatures that require careful creation and a suitable habitat. After creating a sloth, you’re responsible for feeding them, providing fulfilling activities, and giving them opportunities to exercise and rest."}]},{"type":"paragraph","inlineContent":[{"type":"text","text":"Every sloth has a "},{"type":"reference","isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/name"},{"type":"text","text":" and "},{"type":"reference","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/color-swift.property","isActive":true},{"text":". You can optionally provide a ","type":"text"},{"type":"reference","isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/power-swift.property"},{"text":" if your sloth has special supernatural abilities.","type":"text"}]},{"type":"paragraph","inlineContent":[{"identifier":"slothPower.png","type":"image"}]},{"type":"heading","level":3,"anchor":"Create-a-Sloth","text":"Create a Sloth"},{"inlineContent":[{"text":"To create a standard sloth without any special supernatural powers, you initialize a new instance of the ","type":"text"},{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth","type":"reference","isActive":true},{"text":" structure, and supply a name and a color, as the following code shows:","type":"text"}],"type":"paragraph"},{"syntax":"swift","type":"codeListing","code":["var sloth = Sloth(name: \"Super Sloth\", color: .blue, power: .none)"]},{"type":"paragraph","inlineContent":[{"text":"If your sloth possesses one of the special powers of ","type":"text"},{"type":"codeVoice","code":"ice"},{"type":"text","text":", "},{"code":"fire","type":"codeVoice"},{"text":", ","type":"text"},{"code":"wind","type":"codeVoice"},{"text":", or ","type":"text"},{"type":"codeVoice","code":"lightning"},{"type":"text","text":", you can specify this at creation:"}]},{"code":["var superSloth = Sloth(name: \"Silly Sloth\", color: .green, power: .lightning)"],"type":"codeListing","syntax":"swift"},{"type":"paragraph","inlineContent":[{"text":"If you’re creating a large number of sloths, you can define your own random name generator that conforms to the ","type":"text"},{"isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/NameGenerator","type":"reference"},{"type":"text","text":" protocol, and use it to generate names:"}]},{"type":"codeListing","syntax":"swift","code":["let slothNamer = MyCustomSlothNamer()","var sloths: [Sloth] = []","","for _ in 0...100 {"," let name = slothNamer.generateName(seed: 0)"," var sloth = Sloth(name: name, color: .green, power: .ice)"," "," sloths.append(sloth)","}"]},{"level":3,"text":"Provide a Habitat","type":"heading","anchor":"Provide-a-Habitat"},{"type":"paragraph","inlineContent":[{"text":"Sloths thrive in comfortable habitats. To create a sloth-friendly habitat, you specify whether it’s humid, warm, or both. The following listing creates a habitat that’s humid and warm, which results in a high ","type":"text"},{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Habitat\/comfortLevel","isActive":true,"type":"reference"},{"type":"text","text":":"}]},{"code":["let lovelyHabitat = Habitat(isHumid: true, isWarm: true)"],"type":"codeListing","syntax":"swift"},{"type":"paragraph","inlineContent":[{"text":"After you create a sloth habitat, you’re ready for sloths to sleep in it. Sleeping in a habitat increases the ","type":"text"},{"type":"reference","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/energyLevel","isActive":true},{"text":" of the sloth by the comfort level of the habitat. Sloths sleep for long periods so, by default, your sloth sleeps for 12 hours, but you can also customize this value:","type":"text"}]},{"code":["superSloth.sleep(in: lovelyHabitat)","hyperSloth.sleep(in: lovelyHabitat, for: 2)"],"syntax":"swift","type":"codeListing"},{"text":"Exercise a Sloth","level":3,"type":"heading","anchor":"Exercise-a-Sloth"},{"inlineContent":[{"text":"To keep your sloths happy and fulfilled, you can create activities for them to perform. Define your activities by conforming to the ","type":"text"},{"isActive":true,"type":"reference","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Activity"},{"text":" protocol and implementing the ","type":"text"},{"isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Activity\/perform(with:)","type":"reference"},{"text":" method:","type":"text"}],"type":"paragraph"},{"syntax":"swift","code":["struct Sightseeing: Activity {"," func perform(with sloth: inout Sloth) -> Speed {"," sloth.energyLevel -= 10"," return .slow"," }","}"],"type":"codeListing"},{"level":3,"text":"Feed a Sloth","type":"heading","anchor":"Feed-a-Sloth"},{"inlineContent":[{"text":"Sloths require sustenance to perform activities, so you can feed them ","type":"text"},{"isActive":true,"type":"reference","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/Food"},{"type":"text","text":". Standard sloth food includes leaves and twigs:"}],"type":"paragraph"},{"type":"codeListing","syntax":"swift","code":["superSloth.eat(.largeLeaf)","hyperSloth.eat(.twig)"]},{"text":"Schedule Care for a Sloth","anchor":"Schedule-Care-for-a-Sloth","level":3,"type":"heading"},{"type":"paragraph","inlineContent":[{"type":"text","text":"To make it easy to care for your sloth, SlothCreator provides a "},{"isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/CareSchedule","type":"reference"},{"text":" structure that lets you define activities or foods for your sloth to enjoy at specific times. Create the schedule, then provide a tuple of a ","type":"text"},{"code":"Date","type":"codeVoice"},{"type":"text","text":" and an "},{"type":"reference","isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Activity"},{"text":", or you can use some of the standard care procedures:","type":"text"}]},{"syntax":"swift","type":"codeListing","code":["let events: [(Date, CareSchedule.Event)] = ["," (Date.now, .bedtime),"," (Date(timeIntervalSinceNow: 12*60*60), .breakfast),"," (Date(timeIntervalSinceNow: 13*60*60), .activity(Sightseeing()))","]","","let schedule = CareSchedule(events: events)","superSloth.schedule = schedule"]}]}],"hierarchy":{"paths":[["doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator"]]},"metadata":{"title":"Getting Started with Sloths","roleHeading":"Article","images":[{"identifier":"gettingStarted-card.png","type":"card"}],"role":"article","modules":[{"name":"SlothCreator"}]},"abstract":[{"type":"text","text":"Create a sloth and assign personality traits and abilities."}],"seeAlsoSections":[{"identifiers":["doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/SlothySample","doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth"],"generated":true,"anchor":"Essentials","title":"Essentials"}],"sections":[],"references":{"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/Sloth/power-swift.property":{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/power-swift.property","role":"symbol","fragments":[{"text":"var","kind":"keyword"},{"kind":"text","text":" "},{"kind":"identifier","text":"power"},{"text":": ","kind":"text"},{"text":"Power","preciseIdentifier":"s:12SlothCreator0A0V5PowerO","kind":"typeIdentifier"}],"title":"power","kind":"symbol","abstract":[{"type":"text","text":"The power of the sloth."}],"url":"\/documentation\/slothcreator\/sloth\/power-swift.property","type":"topic"},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/Sloth":{"kind":"symbol","abstract":[{"type":"text","text":"A model representing a sloth."}],"navigatorTitle":[{"text":"Sloth","kind":"identifier"}],"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth","title":"Sloth","url":"\/documentation\/slothcreator\/sloth","role":"symbol","type":"topic","fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"text":"Sloth","kind":"identifier"}]},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/Sloth/Food":{"type":"topic","kind":"symbol","url":"\/documentation\/slothcreator\/sloth\/food","abstract":[{"text":"Food that a sloth can consume.","type":"text"}],"title":"Sloth.Food","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/Food","role":"symbol","fragments":[{"kind":"keyword","text":"struct"},{"text":" ","kind":"text"},{"kind":"identifier","text":"Food"}],"navigatorTitle":[{"text":"Food","kind":"identifier"}]},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/Activity":{"navigatorTitle":[{"kind":"identifier","text":"Activity"}],"type":"topic","role":"symbol","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Activity","abstract":[{"type":"text","text":"A type that declares an activity a Sloth can perform."}],"fragments":[{"text":"protocol","kind":"keyword"},{"kind":"text","text":" "},{"kind":"identifier","text":"Activity"}],"title":"Activity","kind":"symbol","url":"\/documentation\/slothcreator\/activity"},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/Sloth/name":{"abstract":[{"text":"The name of the sloth.","type":"text"}],"fragments":[{"text":"var","kind":"keyword"},{"kind":"text","text":" "},{"kind":"identifier","text":"name"},{"text":": ","kind":"text"},{"preciseIdentifier":"s:SS","kind":"typeIdentifier","text":"String"}],"title":"name","url":"\/documentation\/slothcreator\/sloth\/name","role":"symbol","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/name","type":"topic","kind":"symbol"},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/SlothySample":{"title":"Slothy: Integrating SlothCreator into an App","kind":"article","images":[{"identifier":"slothy-card.png","type":"card"}],"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/SlothySample","abstract":[{"type":"text","text":"Integrate SlothCreator into an iOS app for creating and caring"},{"text":" ","type":"text"},{"text":"for custom sloths.","type":"text"}],"role":"sampleCode","type":"topic","url":"\/documentation\/slothcreator\/slothysample"},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/Activity/perform(with:)":{"type":"topic","kind":"symbol","url":"\/documentation\/slothcreator\/activity\/perform(with:)","abstract":[{"text":"Performs the work or sequence of actions for an activity.","type":"text"}],"title":"perform(with:)","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Activity\/perform(with:)","role":"symbol","required":true,"fragments":[{"text":"func","kind":"keyword"},{"text":" ","kind":"text"},{"kind":"identifier","text":"perform"},{"text":"(","kind":"text"},{"kind":"externalParam","text":"with"},{"text":": ","kind":"text"},{"kind":"keyword","text":"inout"},{"text":" ","kind":"text"},{"text":"Sloth","kind":"typeIdentifier","preciseIdentifier":"s:12SlothCreator0A0V"},{"text":") -> ","kind":"text"},{"text":"Speed","kind":"typeIdentifier","preciseIdentifier":"s:12SlothCreator5SpeedO"}]},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator":{"url":"\/documentation\/slothcreator","title":"SlothCreator","kind":"symbol","images":[{"type":"icon","identifier":"slothCreator-icon.png"}],"type":"topic","abstract":[{"type":"text","text":"Catalog sloths you find in nature and create new adorable virtual sloths."}],"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator","role":"collection"},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/CareSchedule":{"kind":"symbol","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/CareSchedule","navigatorTitle":[{"kind":"identifier","text":"CareSchedule"}],"fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"text":"CareSchedule","kind":"identifier"}],"abstract":[{"text":"A schedule to maintain the health and happiness of a sloth.","type":"text"}],"type":"topic","role":"symbol","url":"\/documentation\/slothcreator\/careschedule","title":"CareSchedule"},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/NameGenerator":{"type":"topic","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/NameGenerator","url":"\/documentation\/slothcreator\/namegenerator","kind":"symbol","abstract":[{"type":"text","text":"A type that generates names for sloths."}],"role":"symbol","navigatorTitle":[{"kind":"identifier","text":"NameGenerator"}],"title":"NameGenerator","fragments":[{"text":"protocol","kind":"keyword"},{"text":" ","kind":"text"},{"text":"NameGenerator","kind":"identifier"}]},"slothPower.png":{"variants":[{"traits":["2x","light"],"url":"\/images\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/slothPower@2x.png"},{"traits":["2x","dark"],"url":"\/images\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/slothPower~dark@2x.png"}],"alt":"A diagram with the five sloth power types: ice, fire, wind, lightning, and none.","type":"image","identifier":"slothPower.png"},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/Habitat/comfortLevel":{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Habitat\/comfortLevel","role":"symbol","title":"comfortLevel","type":"topic","url":"\/documentation\/slothcreator\/habitat\/comfortlevel","abstract":[{"type":"text","text":"An indicator of how comfortable a sloth might find the habitat."}],"fragments":[{"kind":"keyword","text":"var"},{"text":" ","kind":"text"},{"text":"comfortLevel","kind":"identifier"},{"text":": ","kind":"text"},{"kind":"typeIdentifier","text":"Int","preciseIdentifier":"s:Si"}],"kind":"symbol"},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/Sloth/energyLevel":{"type":"topic","role":"symbol","url":"\/documentation\/slothcreator\/sloth\/energylevel","title":"energyLevel","fragments":[{"text":"var","kind":"keyword"},{"text":" ","kind":"text"},{"text":"energyLevel","kind":"identifier"},{"kind":"text","text":": "},{"text":"Int","preciseIdentifier":"s:Si","kind":"typeIdentifier"}],"abstract":[{"text":"The energy level of the sloth.","type":"text"}],"kind":"symbol","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/energyLevel"},"doc://slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator/documentation/SlothCreator/Sloth/color-swift.property":{"title":"color","kind":"symbol","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/color-swift.property","abstract":[{"text":"The color of the sloth.","type":"text"}],"role":"symbol","fragments":[{"text":"var","kind":"keyword"},{"text":" ","kind":"text"},{"kind":"identifier","text":"color"},{"kind":"text","text":": "},{"kind":"typeIdentifier","preciseIdentifier":"s:12SlothCreator0A0V5ColorO","text":"Color"}],"type":"topic","url":"\/documentation\/slothcreator\/sloth\/color-swift.property"},"slothy-card.png":{"variants":[{"url":"\/images\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/slothy-card@2x.png","traits":["2x","light"]}],"alt":"Two screenshots showing the Slothy app. The first screenshot shows a sloth map and the second screenshot shows a sloth power picker.","type":"image","identifier":"slothy-card.png"},"gettingStarted-card.png":{"variants":[{"url":"\/images\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/gettingStarted-card@2x.png","traits":["2x","light"]}],"alt":null,"type":"image","identifier":"gettingStarted-card.png"},"slothCreator-icon.png":{"variants":[{"url":"\/images\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/slothCreator-icon@2x.png","traits":["2x","light"]}],"alt":"A technology icon representing the SlothCreator framework.","type":"image","identifier":"slothCreator-icon.png"}}}