1 line
18 KiB
JSON
1 line
18 KiB
JSON
{"abstract":[{"text":"Create a sloth and assign personality traits and abilities.","type":"text"}],"primaryContentSections":[{"kind":"content","content":[{"anchor":"Overview","level":2,"text":"Overview","type":"heading"},{"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 "},{"isActive":true,"type":"reference","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth\/name"},{"type":"text","text":" and "},{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth\/color-swift.property","type":"reference","isActive":true},{"text":". You can optionally provide a ","type":"text"},{"type":"reference","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth\/power-swift.property","isActive":true},{"type":"text","text":" if your sloth has special supernatural abilities."}]},{"inlineContent":[{"type":"image","identifier":"slothPower.png"}],"type":"paragraph"},{"text":"Create a Sloth","type":"heading","level":3,"anchor":"Create-a-Sloth"},{"type":"paragraph","inlineContent":[{"type":"text","text":"To create a standard sloth without any special supernatural powers, you initialize a new instance of the "},{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth","isActive":true,"type":"reference"},{"type":"text","text":" structure, and supply a name and a color, as the following code shows:"}]},{"code":["var sloth = Sloth(name: \"Super Sloth\", color: .blue, power: .none)"],"syntax":"swift","type":"codeListing"},{"inlineContent":[{"text":"If your sloth possesses one of the special powers of ","type":"text"},{"type":"codeVoice","code":"ice"},{"text":", ","type":"text"},{"type":"codeVoice","code":"fire"},{"type":"text","text":", "},{"type":"codeVoice","code":"wind"},{"type":"text","text":", or "},{"type":"codeVoice","code":"lightning"},{"type":"text","text":", you can specify this at creation:"}],"type":"paragraph"},{"type":"codeListing","syntax":"swift","code":["var superSloth = Sloth(name: \"Silly Sloth\", color: .green, power: .lightning)"]},{"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,"type":"reference","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/NameGenerator"},{"type":"text","text":" protocol, and use it to generate names:"}],"type":"paragraph"},{"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)","}"],"type":"codeListing","syntax":"swift"},{"type":"heading","text":"Provide a Habitat","level":3,"anchor":"Provide-a-Habitat"},{"type":"paragraph","inlineContent":[{"type":"text","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 "},{"isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Habitat\/comfortLevel","type":"reference"},{"text":":","type":"text"}]},{"code":["let lovelyHabitat = Habitat(isHumid: true, isWarm: true)"],"syntax":"swift","type":"codeListing"},{"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","isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth\/energyLevel"},{"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"}],"type":"paragraph"},{"syntax":"swift","type":"codeListing","code":["superSloth.sleep(in: lovelyHabitat)","hyperSloth.sleep(in: lovelyHabitat, for: 2)"]},{"level":3,"text":"Exercise a Sloth","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"},{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Activity","isActive":true,"type":"reference"},{"type":"text","text":" protocol and implementing the "},{"type":"reference","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Activity\/perform(with:)","isActive":true},{"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,"type":"heading","anchor":"Feed-a-Sloth","text":"Feed a Sloth"},{"type":"paragraph","inlineContent":[{"text":"Sloths require sustenance to perform activities, so you can feed them ","type":"text"},{"type":"reference","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth\/Food","isActive":true},{"text":". Standard sloth food includes leaves and twigs:","type":"text"}]},{"type":"codeListing","syntax":"swift","code":["superSloth.eat(.largeLeaf)","hyperSloth.eat(.twig)"]},{"type":"heading","level":3,"text":"Schedule Care for a Sloth","anchor":"Schedule-Care-for-a-Sloth"},{"type":"paragraph","inlineContent":[{"text":"To make it easy to care for your sloth, SlothCreator provides a ","type":"text"},{"isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.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"},{"type":"codeVoice","code":"Date"},{"type":"text","text":" and an "},{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Activity","isActive":true,"type":"reference"},{"type":"text","text":", or you can use some of the standard care procedures:"}]},{"type":"codeListing","syntax":"swift","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"]}]}],"variants":[{"traits":[{"interfaceLanguage":"swift"}],"paths":["\/documentation\/slothcreator\/gettingstarted"]}],"identifier":{"interfaceLanguage":"swift","url":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/GettingStarted"},"schemaVersion":{"major":0,"patch":0,"minor":3},"hierarchy":{"paths":[["doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator"]]},"sections":[],"seeAlsoSections":[{"generated":true,"title":"Essentials","anchor":"Essentials","identifiers":["doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/SlothySample","doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth"]}],"kind":"article","metadata":{"modules":[{"name":"SlothCreator"}],"title":"Getting Started with Sloths","roleHeading":"Article","role":"article","images":[{"identifier":"gettingStarted-card.png","type":"card"}]},"references":{"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/Sloth/power-swift.property":{"fragments":[{"text":"var","kind":"keyword"},{"kind":"text","text":" "},{"text":"power","kind":"identifier"},{"kind":"text","text":": "},{"text":"Power","kind":"typeIdentifier","preciseIdentifier":"s:12SlothCreator0A0V5PowerO"}],"type":"topic","kind":"symbol","title":"power","abstract":[{"text":"The power of the sloth.","type":"text"}],"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth\/power-swift.property","url":"\/documentation\/slothcreator\/sloth\/power-swift.property","role":"symbol"},"slothy-card.png":{"identifier":"slothy-card.png","alt":"Two screenshots showing the Slothy app. The first screenshot shows a sloth map and the second screenshot shows a sloth power picker.","variants":[{"url":"\/images\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/slothy-card@2x.png","traits":["2x","light"]}],"type":"image"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/CareSchedule":{"title":"CareSchedule","abstract":[{"text":"A schedule to maintain the health and happiness of a sloth.","type":"text"}],"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/CareSchedule","kind":"symbol","role":"symbol","url":"\/documentation\/slothcreator\/careschedule","navigatorTitle":[{"kind":"identifier","text":"CareSchedule"}],"fragments":[{"text":"struct","kind":"keyword"},{"kind":"text","text":" "},{"text":"CareSchedule","kind":"identifier"}],"type":"topic"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/Sloth/name":{"kind":"symbol","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth\/name","fragments":[{"text":"var","kind":"keyword"},{"kind":"text","text":" "},{"text":"name","kind":"identifier"},{"text":": ","kind":"text"},{"preciseIdentifier":"s:SS","text":"String","kind":"typeIdentifier"}],"role":"symbol","abstract":[{"type":"text","text":"The name of the sloth."}],"title":"name","url":"\/documentation\/slothcreator\/sloth\/name","type":"topic"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/Activity/perform(with:)":{"role":"symbol","url":"\/documentation\/slothcreator\/activity\/perform(with:)","kind":"symbol","type":"topic","title":"perform(with:)","fragments":[{"kind":"keyword","text":"func"},{"text":" ","kind":"text"},{"text":"perform","kind":"identifier"},{"text":"(","kind":"text"},{"text":"with","kind":"externalParam"},{"text":": ","kind":"text"},{"kind":"keyword","text":"inout"},{"text":" ","kind":"text"},{"preciseIdentifier":"s:12SlothCreator0A0V","text":"Sloth","kind":"typeIdentifier"},{"kind":"text","text":") -> "},{"text":"Speed","preciseIdentifier":"s:12SlothCreator5SpeedO","kind":"typeIdentifier"}],"abstract":[{"type":"text","text":"Performs the work or sequence of actions for an activity."}],"required":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Activity\/perform(with:)"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/Sloth":{"title":"Sloth","navigatorTitle":[{"text":"Sloth","kind":"identifier"}],"type":"topic","url":"\/documentation\/slothcreator\/sloth","role":"symbol","kind":"symbol","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth","fragments":[{"text":"struct","kind":"keyword"},{"text":" ","kind":"text"},{"kind":"identifier","text":"Sloth"}],"abstract":[{"type":"text","text":"A model representing a sloth."}]},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/SlothySample":{"type":"topic","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","images":[{"type":"card","identifier":"slothy-card.png"}],"url":"\/documentation\/slothcreator\/slothysample","kind":"article","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/SlothySample","title":"Slothy: Integrating SlothCreator into an App"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/Sloth/energyLevel":{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth\/energyLevel","role":"symbol","url":"\/documentation\/slothcreator\/sloth\/energylevel","fragments":[{"text":"var","kind":"keyword"},{"kind":"text","text":" "},{"text":"energyLevel","kind":"identifier"},{"kind":"text","text":": "},{"preciseIdentifier":"s:Si","text":"Int","kind":"typeIdentifier"}],"title":"energyLevel","abstract":[{"text":"The energy level of the sloth.","type":"text"}],"kind":"symbol","type":"topic"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/Habitat/comfortLevel":{"title":"comfortLevel","abstract":[{"text":"An indicator of how comfortable a sloth might find the habitat.","type":"text"}],"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Habitat\/comfortLevel","type":"topic","fragments":[{"text":"var","kind":"keyword"},{"text":" ","kind":"text"},{"text":"comfortLevel","kind":"identifier"},{"kind":"text","text":": "},{"preciseIdentifier":"s:Si","text":"Int","kind":"typeIdentifier"}],"url":"\/documentation\/slothcreator\/habitat\/comfortlevel","kind":"symbol","role":"symbol"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/Sloth/Food":{"type":"topic","fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"text":"Food","kind":"identifier"}],"kind":"symbol","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth\/Food","title":"Sloth.Food","role":"symbol","abstract":[{"text":"Food that a sloth can consume.","type":"text"}],"url":"\/documentation\/slothcreator\/sloth\/food","navigatorTitle":[{"text":"Food","kind":"identifier"}]},"gettingStarted-card.png":{"identifier":"gettingStarted-card.png","alt":null,"variants":[{"url":"\/images\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/gettingStarted-card@2x.png","traits":["2x","light"]}],"type":"image"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/Activity":{"abstract":[{"type":"text","text":"A type that declares an activity a Sloth can perform."}],"url":"\/documentation\/slothcreator\/activity","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Activity","type":"topic","fragments":[{"text":"protocol","kind":"keyword"},{"kind":"text","text":" "},{"text":"Activity","kind":"identifier"}],"navigatorTitle":[{"kind":"identifier","text":"Activity"}],"role":"symbol","kind":"symbol","title":"Activity"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/Sloth/color-swift.property":{"type":"topic","abstract":[{"text":"The color of the sloth.","type":"text"}],"role":"symbol","url":"\/documentation\/slothcreator\/sloth\/color-swift.property","kind":"symbol","fragments":[{"text":"var","kind":"keyword"},{"text":" ","kind":"text"},{"text":"color","kind":"identifier"},{"kind":"text","text":": "},{"text":"Color","kind":"typeIdentifier","preciseIdentifier":"s:12SlothCreator0A0V5ColorO"}],"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/Sloth\/color-swift.property","title":"color"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator":{"url":"\/documentation\/slothcreator","type":"topic","abstract":[{"text":"Catalog sloths you find in nature and create new adorable virtual sloths.","type":"text"}],"images":[{"identifier":"slothCreator-icon.png","type":"icon"}],"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator","title":"SlothCreator","role":"collection","kind":"symbol"},"doc://slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator/documentation/SlothCreator/NameGenerator":{"url":"\/documentation\/slothcreator\/namegenerator","kind":"symbol","abstract":[{"text":"A type that generates names for sloths.","type":"text"}],"type":"topic","navigatorTitle":[{"text":"NameGenerator","kind":"identifier"}],"title":"NameGenerator","role":"symbol","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/documentation\/SlothCreator\/NameGenerator","fragments":[{"text":"protocol","kind":"keyword"},{"text":" ","kind":"text"},{"text":"NameGenerator","kind":"identifier"}]},"slothPower.png":{"identifier":"slothPower.png","alt":"A diagram with the five sloth power types: ice, fire, wind, lightning, and none.","variants":[{"url":"\/images\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/slothPower@2x.png","traits":["2x","light"]},{"traits":["2x","dark"],"url":"\/images\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/slothPower~dark@2x.png"}],"type":"image"},"slothCreator-icon.png":{"identifier":"slothCreator-icon.png","alt":"A technology icon representing the SlothCreator framework.","variants":[{"url":"\/images\/slothcreatorbuildingdoccdocumentationinxcode-3.SlothCreator\/slothCreator-icon@2x.png","traits":["2x","light"]}],"type":"image"}}} |