1 line
18 KiB
JSON
Raw Normal View History

{"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, youre 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 youre 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 its humid, warm, or both. The following listing creates a habitat thats 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, youre ready for sloths to sleep in it. Sleeping in a habitat increases the ","type":"text"},{"type":"reference","isActive":true,"i